FROMXML( record, xmlstring ,[ONFAIL(transform )])
record | The RECORD structure to produce. Each field must specify the XPATH to the data in the xmlstring that it should hold. |
xmlstring | A string containing the XML to convert. |
ONFAIL | Optional. Specifies a transform to handle errors in the XML. |
transform | A TRANSFORM structure matching the record structure of the first parameter. |
Return: | FROMXML returns a single row (record). |
The FROMXML function returns a single row (record) in the record format from the specified xmlstring. This may be used anywhere a single row can be used (similar to the ROW function).
Example:
namesRec := RECORD UNSIGNED2 EmployeeID{xpath('EmpID')}; STRING10 Firstname{xpath('FName')}; STRING10 Lastname{xpath('LName')}; END; x := '<Row><FName>George</FName><LName>Jetson</LName><EmpID>42</EmpID></Row>'; rec := FROMXML(namesRec,x); OUTPUT(rec);
Example with Error handling and bad XML:
namesRec := RECORD UNSIGNED2 EmployeeID{xpath('EmpID')}; STRING20 Firstname{xpath('FName')}; STRING20 Lastname{xpath('LName')}; END; x := '<Row><FName>George</FName><LName><unmatchedtag>Jetson</LName><EmpID>42</EmpID></Row>'; namesRec createFailure() := TRANSFORM SELF.FirstName := FAILMESSAGE; SELF := []; END; rec := FROMXML(namesRec,x,ONFAIL(createFailure())); OUTPUT(rec);