FROMXML

FROMXML( record, xmlstring ,[ONFAIL(transform )])

recordThe RECORD structure to produce. Each field must specify the XPATH to the data in the xmlstring that it should hold.
xmlstringA string containing the XML to convert.
ONFAILOptional. Specifies a transform to handle errors in the XML.
transformA 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);

See Also: ROW, TOXML