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

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 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 parse-xml-options =  "http://www.zorba-xquery.com/modules/xml-options";

Related Documentation

For more details please also see:

Namespaces
err http://www.w3.org/xqt-errors
parse-xml http://www.zorba-xquery.com/modules/xml
parse-xml-options http://www.zorba-xquery.com/modules/xml-options
ver http://www.zorba-xquery.com/options/versioning
zerr http://www.zorba-xquery.com/errors
Function Summary
External parse ( $xml-string as xs:string?, $options as element(parse-xml-options: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
External parse back to 'Function Summary'
declare function parse-xml:parse (
            $xml-string as xs:string?,
            $options as element(parse-xml-options: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 parse-xml = "http://www.zorba-xquery.com/modules/xml";
   import schema namespace opt = "http://www.zorba-xquery.com/modules/xml-options";
   parse-xml: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 parse-xml: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 parse-xml: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 parse-xml: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 parse-xml: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:

blog comments powered by Disqus