This module provides functions for reading XML files from string inputs. It allows reading of well-formed XML documents as well as well-formed external parsed entities, described by XML 1.0 Well-Formed Parsed Entities. The functions can also perform Schema and DTD validation of the input documents.
The following example parses a sequence of XML elements and returns them in a streaming fashion - each at a time:
import module namespace x = "http://zorba.io/modules/xml"; import schema namespace opt = "http://zorba.io/modules/xml-options"; x:parse( "<from1>Jani</from1><from2>Jani</from2><from3>Jani</from3>", <opt:options> <opt:parse-external-parsed-entity/> </opt:options> )
Another useful option allows to skip an arbitrary number of levels before returning a sequence of nodes as shown in the following example:
import module namespace x = "http://zorba.io/modules/xml"; import schema namespace opt = "http://zorba.io/modules/xml-options"; x:parse( "<root> <from1>Jani1</from1> <from2>Jani2</from2> <from3>Jani3</from3> </root>", <opt:options> <opt:parse-external-parsed-entity opt:skip-root-nodes="1"/> </opt:options> )
canonicalize
($xml-string as xs:string) as xs:string
A function to canonicalize the given XML string, that is, transform it into Canonical XML as defined by Canonical XML . |
canonicalize
($xml-string as xs:string, $options as element(opt:options)) as xs:string
A function to canonicalize the given XML string, that is, transform it into Canonical XML as defined by Canonical XML . |
parse
($xml-string as xs:string?, $options as element(opt:options)?) as node()* external
A function to parse XML files and fragments (i. |
declare function x:canonicalize($xml-string as xs:string) as xs:string
A function to canonicalize the given XML string, that is, transform it into Canonical XML as defined by Canonical XML.
Note: This function is not streamable. If a streamable string is used as input for the function it will be materialized.
Note: This function sets the XML_PARSE_NOERROR option when parsing the XML input.
declare function x:canonicalize($xml-string as xs:string, $options as element(opt:options)) as xs:string
A function to canonicalize the given XML string, that is, transform it into Canonical XML as defined by Canonical XML.
This version of the function allows specifying certain options to be used when initially parsing the XML string. These are of the same form as the options to x:parse#2(), although the following options are currently ignored for this function:
Note: This function is not streamable, if a streamable string is used as input for the function it will be materialized.
Note: This function sets the XML_PARSE_NOERROR option when parsing the XML input.
declare function x:parse($xml-string as xs:string?, $options as element(opt:options)?) as node()* external
A function to parse XML files and fragments (i.e. external general parsed entities).
The functions takes two arguments: the first one is the string to be parsed and the second argument is an <options/> element that passes a list of options to the parsing function. They are described below. The options element must conform to the xml-options:options element type from the xml-options.xsd schema. Some of these will be passed to the underlying library (LibXml2) and further documentation for them can be found at LibXml2 parser.
The list of available options:An example that sets the base-uri of the parsed external entities:
import module namespace x = "http://zorba.io/modules/xml"; import schema namespace opt = "http://zorba.io/modules/xml-options"; x:parse("<from1>Jani</from1><from2>Jani</from2><from3>Jani</from3>", <opt:options> <opt:base-uri opt:value="urn:test"/> <opt:parse-external-parsed-entity/> </opt:options> )