http://www.zorba-xquery.com/modules/xml ZC

Module Description
Before using any of the functions below please remember to import the module namespace:
import module namespace x = "http://www.zorba-xquery.com/modules/xml";

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://www.zorba-xquery.com/modules/xml";
 import schema namespace opt = "http://www.zorba-xquery.com/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://www.zorba-xquery.com/modules/xml";
 import schema namespace opt = "http://www.zorba-xquery.com/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>
 )
 

Author:

Nicolae Brinza, Juan Zacarias

XQuery version and encoding for this module:

xquery version "3.0" encoding "utf-8";

Zorba version for this module:

The latest version of this module is 2.0. For more information about module versioning in Zorba please check out this resource.

Module Resources
Module Dependencies

Imported modules:

Imported schemas:

Please note that the schemas are not automatically imported in the modules that import this module.
In order to import and use the schemas, please add:

import schema namespace opt =  "http://www.zorba-xquery.com/modules/xml-options";

Related Documentation

For more details please also see:

Namespaces
err http://www.w3.org/xqt-errors
opt http://www.zorba-xquery.com/modules/xml-options
schema http://www.zorba-xquery.com/modules/schema
ver http://www.zorba-xquery.com/options/versioning
x http://www.zorba-xquery.com/modules/xml
zerr http://www.zorba-xquery.com/errors
Function Summary
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.
External parse ( $xml-string as xs:string?, $options as element(opt:options)? ) as node()*
A function to parse XML files and fragments (i.
parse-xml-fragment ( $xml-string as xs:string?, $options as xs:string ) as node()*
Note: this function is included for backwards compatibility purposes.
parse-xml-fragment ( $xml-string as xs:string?, $base-uri as xs:string, $options as xs:string ) as node()*
Note: this function is included for backwards compatibility purposes.
Functions
canonicalize back to 'Function Summary'
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.

Parameters:
Returns:
Errors:

canonicalize back to 'Function Summary'
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.

Parameters:
Returns:
Errors:

External parse back to 'Function Summary'
declare function x:parse (
            $xml-string as xs:string?,
            $options as element(opt:options)?
) as node()*

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://www.zorba-xquery.com/modules/xml";
   import schema namespace opt = "http://www.zorba-xquery.com/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>
   )
 

Parameters:
Returns:
Errors:
Examples:

parse-xml-fragment back to 'Function Summary'

Deprecated

declare function x:parse-xml-fragment (
            $xml-string as xs:string?,
            $options as xs:string
) as node()*


Note: this function is included for backwards compatibility purposes. It is recommended that you use the x:parse() function instead.


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 a flags string (eEdDsSlLwWfF]*(;[\p{L}]*)?) selecting the options described below.

The convention for the flags is that a lower-case letter enables an option and the corresponding upper-case letter disables it; specifying both is an error; specifying neither leaves it implementation-defined whether the option is enabled or disabled. Specifying the same option twice is not an error, but specifying inconsistent options (for example "eE") is a dynamic error. The options are:

Parameters:
Returns:
Errors:

parse-xml-fragment back to 'Function Summary'

Deprecated

declare function x:parse-xml-fragment (
            $xml-string as xs:string?,
            $base-uri as xs:string,
            $options as xs:string
) as node()*


Note: this function is included for backwards compatibility purposes. It is recommended that you use the x:parse() function instead.


A function to parse XML files and fragments. The behavior is the same as the parse-xml-fragment with two arguments.

Parameters:
Returns:
Errors: