C Schemas

Two functions in this specification, fn:analyze-string and fn:json-to-xml, produce results in the form of an XDM node tree that must conform to a specified schema. In both cases the elements in the result are in the namespace http://www.w3.org/2005/xpath-functions, which is therefore the target namespace of the relevant schema document.

The schema for this namespace is organized as three schema documents. The first is a simple umbrella document that includes the other two. A copy can be found at xpath-functions.xsd:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
    elementFormDefault="qualified"
    targetNamespace="http://www.w3.org/2005/xpath-functions">
    
    <!-- 
     * This is a schema for the namespace http://www.w3.org/2005/xpath-functions
     *
     * The schema is made available under the terms of the W3C software notice and license
     * at http://www.w3.org/Consortium/Legal/copyright-software-19980720
     *
     * The schema includes two schema documents, containing definitions of the structure
     * of the results of the fn:analyze-string and fn:json-to-xml functions respectively.
     *
    -->
    
    <xs:include schemaLocation="analyze-string.xsd"/>
    <xs:include schemaLocation="schema-for-json.xsd"/>
</xs:schema>

C.1 Schema for the result of fn:analyze-string

This schema describes the output of the function fn:analyze-string.

The schema is reproduced below, and can also be found in analyze-string.xsd:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
    targetNamespace="http://www.w3.org/2005/xpath-functions"
    xmlns:fn="http://www.w3.org/2005/xpath-functions"
    elementFormDefault="qualified">
    
    <!-- 
     * This is a schema for the XML representation of JSON used as the target for the
     * function fn:analyze-string()
     *
     * The schema is made available under the terms of the W3C software notice and license
     * at http://www.w3.org/Consortium/Legal/copyright-software-19980720
     *
    -->

    <xs:element name="analyze-string-result" type="fn:analyze-string-result-type"/>
    <xs:element name="match" type="fn:match-type"/>
    <xs:element name="non-match" type="xs:string"/>
    <xs:element name="group" type="fn:group-type"/>
    
    <xs:complexType name="analyze-string-result-type" mixed="true">
        <xs:choice minOccurs="0" maxOccurs="unbounded">
            <xs:element ref="fn:match"/>
            <xs:element ref="fn:non-match"/>
        </xs:choice>
    </xs:complexType>
        
    <xs:complexType name="match-type" mixed="true">
        <xs:sequence>
            <xs:element ref="fn:group" minOccurs="0" maxOccurs="unbounded"/>
        </xs:sequence>
    </xs:complexType>
    
    <xs:complexType name="group-type" mixed="true">
        <xs:sequence>
            <xs:element ref="fn:group" minOccurs="0" maxOccurs="unbounded"/>
        </xs:sequence>
        <xs:attribute name="nr" type="xs:positiveInteger"/>
    </xs:complexType>    
 
</xs:schema>

C.2 Schema for the result of fn:json-to-xml

This schema describes the output of the function fn:json-to-xml, and the input to the function fn:xml-to-json.

The schema is reproduced below, and can also be found in schema-for-json.xsd:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
    elementFormDefault="qualified"
    targetNamespace="http://www.w3.org/2005/xpath-functions"
    xmlns:j="http://www.w3.org/2005/xpath-functions">
    
    <!-- 
     * This is a schema for the XML representation of JSON used as the target for the
     * function fn:json-to-xml()
     *
     * The schema is made available under the terms of the W3C software notice and license
     * at http://www.w3.org/Consortium/Legal/copyright-software-19980720
     *
    -->
    
    <xs:element name="map" type="j:mapType">
        <xs:unique name="unique-key">
            <xs:selector xpath="*"/>
            <xs:field xpath="@key"/>
            <xs:field xpath="@escaped-key"/>
        </xs:unique>
    </xs:element>
    
    <xs:element name="array" type="j:arrayType"/>
    
    <xs:element name="string" type="j:stringType"/>
    
    <xs:element name="number" type="j:numberType"/>
    
    <xs:element name="boolean" type="j:booleanType"/>
    
    <xs:element name="null" type="j:nullType"/>
    
    <xs:complexType name="nullType">
        <xs:sequence/>
        <xs:anyAttribute processContents="skip" namespace="##other"/>
    </xs:complexType>
    
    <xs:complexType name="booleanType">
        <xs:simpleContent>
            <xs:extension base="xs:boolean">
                <xs:anyAttribute processContents="skip" namespace="##other"/>
            </xs:extension>
        </xs:simpleContent>
    </xs:complexType>
    
    <xs:complexType name="stringType">
        <xs:simpleContent>
            <xs:extension base="xs:string">
                <xs:attribute name="escaped" type="xs:boolean" use="optional" default="false"/>
                <xs:anyAttribute processContents="skip" namespace="##other"/>
            </xs:extension>
        </xs:simpleContent>
    </xs:complexType>
    
    <xs:simpleType name="finiteNumberType">
        <xs:restriction base="xs:double">
            <!-- exclude positive and negative infinity, and NaN -->
            <xs:minExclusive value="-INF"/>
            <xs:maxExclusive value="INF"/>
        </xs:restriction>
    </xs:simpleType>
    
    <xs:complexType name="numberType">
        <xs:simpleContent>
            <xs:extension base="j:finiteNumberType">
                <xs:anyAttribute processContents="skip" namespace="##other"/>
            </xs:extension>
        </xs:simpleContent>
    </xs:complexType>
    
    <xs:complexType name="arrayType">
        <xs:choice minOccurs="0" maxOccurs="unbounded">
            <xs:element ref="j:map"/>
            <xs:element ref="j:array"/>
            <xs:element ref="j:string"/>
            <xs:element ref="j:number"/>
            <xs:element ref="j:boolean"/>
            <xs:element ref="j:null"/>
        </xs:choice>
        <xs:anyAttribute processContents="skip" namespace="##other"/>
    </xs:complexType>
    
    <xs:complexType name="mapWithinMapType">
        <xs:complexContent>
            <xs:extension base="j:mapType">
                <xs:attributeGroup ref="j:key-group"/>
            </xs:extension>
        </xs:complexContent>
    </xs:complexType>
    
    <xs:complexType name="arrayWithinMapType">
        <xs:complexContent>
            <xs:extension base="j:arrayType">
                <xs:attributeGroup ref="j:key-group"/>
            </xs:extension>
        </xs:complexContent>
    </xs:complexType>
    
    <xs:complexType name="stringWithinMapType">
        <xs:simpleContent>
            <xs:extension base="j:stringType">
                <xs:attributeGroup ref="j:key-group"/>
            </xs:extension>
        </xs:simpleContent>
    </xs:complexType>
    
    <xs:complexType name="numberWithinMapType">
        <xs:simpleContent>
            <xs:extension base="j:numberType">
                <xs:attributeGroup ref="j:key-group"/>
            </xs:extension>
        </xs:simpleContent>
    </xs:complexType>
    
    <xs:complexType name="booleanWithinMapType">
        <xs:simpleContent>
            <xs:extension base="j:booleanType">
                <xs:attributeGroup ref="j:key-group"/>
            </xs:extension>
        </xs:simpleContent>
    </xs:complexType>
    
    <xs:complexType name="nullWithinMapType">
        <xs:attributeGroup ref="j:key-group"/>
    </xs:complexType>
    
    <xs:complexType name="mapType">
        <xs:choice minOccurs="0" maxOccurs="unbounded">
            <xs:element name="map" type="j:mapWithinMapType">
                <xs:unique name="unique-key-2">
                    <xs:selector xpath="*"/>
                    <xs:field xpath="@key"/>
                </xs:unique>
            </xs:element>
            <xs:element name="array" type="j:arrayWithinMapType"/>            
            <xs:element name="string" type="j:stringWithinMapType"/>   
            <xs:element name="number" type="j:numberWithinMapType"/>
            <xs:element name="boolean" type="j:booleanWithinMapType"/>
            <xs:element name="null" type="j:nullWithinMapType"/>
        </xs:choice>
        <xs:anyAttribute processContents="skip" namespace="##other"/>
    </xs:complexType>
    
    <xs:attributeGroup name="key-group">
        <xs:attribute name="key" type="xs:string" use="required"/>
        <xs:attribute name="escaped-key" type="xs:boolean" use="optional" default="false"/>
    </xs:attributeGroup>
    
</xs:schema>