%XML is used as the second operand of the XML-SAX and XML-INTO operation codes to specify the XML document to be parsed, and the options to control how the document is parsed. %XML does not return a value, and it cannot be specified anywhere other than for the XML-SAX and XML-INTO operation codes.
The first operand specifies the document to be parsed. It can be a constant or variable character or UCS-2 expression containing either an XML document or the name of a file containing an XML document.
optionname1=value1 optionname2=value2
'doc=file allowextra=yes'
' doc=file allowextra=yes '
'ALLOWEXTRA=YES DOC=FILE '
'AllowExtra=Yes Doc=File '
| Option string | The problem with the option string |
|---|---|
| 'doc = file' | Spaces around the equal sign are not allowed |
| 'allowextra' | Each option must have an equal sign and a value |
| 'badopt=yes' | Only valid options are allowed |
| 'allowextra=ok' | The 'allowextra' value can only be 'yes' or 'no' |
The valid options and values depend on the context of the %XML built-in function. See XML-SAX (Parse an XML Document) and XML-INTO (Parse an XML Document into a Variable) for a complete list of valid options and values.
'doc=file doc=string'
then the parser will
use the value "string" for the "doc" option.If the parser discovers an invalid option or invalid value, the operation will fail with status code 00352.
// The "options" parameter is omitted. Default values are used for
// all options. Since the default value for the "doc" option is
// always "string", the parser will correctly assume that the first
// parameter contains an XML document.
xmldocument = '<myfld>new value</myfld>';
XML-INTO myfld %XML(xmldocument);
// The "options" parameter is specified as a literal with two options.
XML-INTO myds %XML(xmldocument : 'allowmissing=yes allowextra=yes');
// The "options" parameter is specified as a variable expression
// with two options.
ccsidOpt = 'ccsid=' + %char(ccsid);
XML-SAX %HANDLER(mySaxHandler : myCommArea)
%XML('myinfo.xml' : 'doc=file ' + ccsidOpt);
For more examples of %XML, see XML-SAX (Parse an XML Document) and XML-INTO (Parse an XML Document into a Variable).
For more information, see XML Operations or Built-in Functions.