The following functions are valid for use only in field definition expressions within a RECORD structure or TRANSFORM function that is used to define the result set from the PARSE function, or the input RECORD structure for a DATASET containing XML data.
XMLTEXT returns the ASCII text from the xmltag.
XMLUNICODE returns the Unicode text from the xmltag.
XMLPROJECT returns the text from the xmltag as a child dataset.
xmltag | A string constant naming the XPATH to the tag containing the data (see the XPATH Support section under the RECORD structure discussion). This may contain an instance number (such as tagname[1]). |
transform | The TRANSFORM function that produces the child dataset. |
Example:
d := DATASET([{'<library><book isbn="123456789X">' + '<author>Bayliss</author><title>A Way Too Far</title></book>' + '<book isbn="1234567801">' + '<author>Smith</author><title>A Way Too Short</title></book>' + '</library>'}], {STRING line }); rform := RECORD STRING author := XMLTEXT('author'); STRING title := XMLTEXT('title'); END; books := PARSE(d,line,rform,XML('library/book')); OUTPUT(books); //******************************************* /* The following XML can be parsed using XMLPROJECT <XML> <Field name='surname' distinct=2> <Value count=3>Halliday</Value> <Value count=2>Chapman</Value> </Field> <XML> */ extractedValueRec := RECORD STRING value; UNSIGNED cnt; END; extractedRec := RECORD STRING name; UNSIGNED cnt; DATASET(extractedValueRec) values; END; x := DATASET([{'<XML>' + '<Field name="surname" distinct="2">' + '<Value count="3">Halliday</Value>' + '<Value count="2">Chapman</Value>' + '</Field>' + '</XML>'}],{STRING line}); extractedRec t1 := TRANSFORM SELF.name := XMLTEXT('@name'); SELF.cnt := (UNSIGNED)XMLTEXT('@distinct'); SELF.values := XMLPROJECT('Value', TRANSFORM(extractedValueRec, SELF.value := XMLTEXT(''), SELF.cnt := (UNSIGNED)XMLTEXT('@count')))(cnt > 1); END; p := PARSE(x, line, t1, XML('XML/Field')); OUTPUT(p);
See Also: PARSE, RECORD Structure, TRANSFORM Structure, DATASET