http://www.zorba-xquery.com/modules/schema-tools

View as XML or JSON.

This module provides funtionality to get sample XMLSchema from XML instances and sample XML instances from XMLSchema. Apache XMLBeans library is used to implement inst2xsd and xsd2inst functions.

Note: Since this module has a Java library dependency a JVM required to be installed on the system. For Windows: jvm.dll is required on the system path ( usually located in "C:\Program Files\Java\jre6\bin\client".

Function Summary

inst2xsd ($instances as element(*)+, $options as element(st-options:inst2xsd-options)?) as document()*

The inst2xsd function takes a set of sample XML instance elements as input and generates a set of sample XMLSchema documents that define the content of the given input.

xsd2inst ($schemas as element(*)+, $rootElementName as xs:string, $options as element(st-options:xsd2inst-options)?) as document()

The xsd2inst function takes a set of XML Schema elements as input and the local name of the root element and generates a document that represents one sample XML instance of the given input schemas.

Functions

inst2xsd#2

declare  function schema-tools:inst2xsd($instances as element(*)+, $options as element(st-options:inst2xsd-options)?) as document()*
The inst2xsd function takes a set of sample XML instance elements as input and generates a set of sample XMLSchema documents that define the content of the given input.
Please consult the official documentation for further information.
Example:
  import module namespace st = "http://www.zorba-xquery.com/modules/schema-tools";
  declare namespace sto =
      "http://www.zorba-xquery.com/modules/schema-tools/schema-tools-options";
  let $instances := (<a><b/><c/></a>, <b/>, <c>ccc</c>)
  let $options  :=
     <sto:inst2xsd-options xmlns:sto=
       "http://www.zorba-xquery.com/modules/schema-tools/schema-tools-options">
       <sto:design>vbd</sto:design>
       <sto:simple-content-types>smart</sto:simple-content-types>
       <sto:use-enumeration>10</sto:use-enumeration>
     </sto:inst2xsd-options>
  return
      st:inst2xsd($instances, $options)
 

Parameters

instances as element(*)
The input XML instance elements
options as element(st-options:inst2xsd-options)
Options:
  • design: Choose the generated schema design
    - rdd: Russian Doll Design - local elements and local types
    - ssd: Salami Slice Design - global elements and local types
    - vbd (default): Venetian Blind Design - local elements and global complex types
  • simple-content-types: type of leaf nodes
    - smart (default): try to find the right simple XMLSchema type
    - always-string: use xsd:string for all simple types
  • use-enumeration: - when there are multiple valid values in a list
    - 1: never use enumeration
    - 2 or more (default 10): use enumeration if less than this number of occurrences - number option
  • verbose: - stdout verbose info
    - true: - output type holder information
    - false (default): no output

Returns

document()*
The generated XMLSchema documents.

xsd2inst#3

declare  function schema-tools:xsd2inst($schemas as element(*)+, $rootElementName as xs:string, $options as element(st-options:xsd2inst-options)?) as document()
The xsd2inst function takes a set of XML Schema elements as input and the local name of the root element and generates a document that represents one sample XML instance of the given input schemas. The local name is searched in schema global element definitions in the order of schemas parameter.
Please consult the official documentation for further information.
Example:
  import module namespace st = "http://www.zorba-xquery.com/modules/schema-tools";
  declare namespace sto =
      "http://www.zorba-xquery.com/modules/schema-tools/schema-tools-options";
  let $xsds  :=
     ( <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
           attributeFormDefault="unqualified"
           elementFormDefault="qualified">
         <xs:element name="a" type="aType"/>
         <xs:complexType name="aType">
           <xs:sequence>
             <xs:element type="xs:string" name="b"/>
             <xs:element type="xs:string" name="c"/>
           </xs:sequence>
         </xs:complexType>
       </xs:schema> )
  let $options :=
    <sto:xsd2inst-options xmlns:sto=
      "http://www.zorba-xquery.com/modules/schema-tools/schema-tools-options">
      <sto:network-downloads>false</sto:network-downloads>
      <sto:no-pvr>false</sto:no-pvr>
      <sto:no-upa>false</sto:no-upa>
    </sto:xsd2inst-options>
  return
      st:xsd2inst($xsds, "a", $options)
 

Parameters

schemas as element(*)
elements representing XMLSchema definitions
rootElementName as xs:string
The local name of the instance root element. If multiple target namespaces are used, first one found - using the sequence order - will be used.
options as element(st-options:xsd2inst-options)
Options:
  • network-downloads: boolean (default false)
    - true allows XMLBeans to use network when resolving schema imports and includes
  • no-pvr: boolean (default false)
    - true to disable particle valid (restriction) rule, false otherwise
  • no-upa: boolean (default false)
    - true to disable unique particle attribution rule, false otherwise

Returns

document()
The generated output document, representing a sample XML instance.