%XML (xmlDocument {:options})
%XML 用作 XML-SAX 和 XML-INTO 操作码的第二个操作数,以指定要解析的 XML 文档以及用于控制文档解析方式的选项。 %XML 不会返回值,并且不能在除 XML-SAX 和 XML-INTO 操作码以外的任何位置指定该值。
第一个操作数指定要解析的文档。 它可以是常量或变量字符,也可以是包含 XML 文档或包含 XML 文档的文件名的 UCS-2 表达式。
第二个操作数指定用于控制如何解释和解析 XML 文档的选项。 它可以是常量或可变字符表达式。 字符表达式的值是表单中指定的零个或零个以上选项的列表
optionname1=value1 optionname2=value2选项名称与等号之间或等号与值之间不允许有空格。 但是,任何数目的空格都可以出现在选项之前,之间或之后。 可以在任何情况下指定选项。 以下是指定 XML-INTO 的 "doc = file" 和 "allowextra = yes" 选项的所有有效方法:
'doc=file allowextra=yes'
' doc=file allowextra=yes '
'ALLOWEXTRA=YES DOC=FILE '
'AllowExtra=Yes Doc=File '以下是 无效 选项字符串:
| 选项字符串 | 选项字符串的问题 |
|---|---|
| 'doc = 文件' | 不允许等号周围有空格 |
| "allowextra" | 每个选项必须具有等号和值 |
| 'b沿用 = yes' | 仅允许有效选项 |
| 'allowextra = ok' | "allowextra" 值只能为 "yes" 或 "no" |
有效选项和值取决于 %XML 内置函数的上下文。 请参阅 XML-SAX (解析 XML 文档) 和 XML-INTO (将 XML 文档解析为变量) ,以获取有效选项和值的完整列表。
多次指定选项时,指定的最后一个值是使用的值。 例如,如果 options 参数具有值
'doc=file doc=string'那么解析器将对 "doc" 选项使用值 "string"。如果解析器发现无效选项或无效值,那么操作将失败,状态码为 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);有关 %XML 的更多示例,请参阅 XML-SAX (解析 XML 文档) 和 XML-INTO (将 XML 文档解析为变量)。