To be defined

Introduction

The following is a draft introduction

This document describes how type definitions described using the Data Schema can be mapped to XML schema definitions by using examples. Given these Data Schemas, providing the mapping to XML schema allows XML tools to directly validate serialized XML data, for example. The XML structure for which this mapping is designed is based on EXI4JSON [exi-for-json].

This document is a work in progress

Below are some examples of payloads in JSON and their corresponding equivalent payloads in XML.

            {
              "brightness": 200,
              "frequency": "fast"
            }
          

<object>
  <brightness>
    <integer>200</integer>
  </brightness>
  <frequency>
    <string>fast</string>
  </frequency>
</object>
[
  520,
  184,
  1314
]
          

<array>
  <number>520</number>
  <number>184</number>
  <number>1314</number>
</array>

Object Definition to XML Schema

Shown below is an example Data Schema of an Object Schema. The object consists of two named literals id (of type integer) and name (of type string) where id is required to be present.
            {
              "type": "object",
              "properties": {
                  "id": {
                          "type": "integer"
                  },
                  "name": {
                          "type": "string"
                  }
              },
              "required": [
                  "id"
              ]
            }
          
When the object is anonymous (i.e. it is the root, or participates in an array definition), the above object definition transforms to the following XML Schema element definition.
            
<xs:element name="object" xmlns:xs="http://www.w3.org/2001/XMLSchema">
              <xs:complexType>
                  <xs:all>
                      <xs:element name="id">
                          <xs:complexType>
                            <xs:sequence>
                              <xs:element name="integer" type="xs:integer" />
                            </xs:sequence>
                          </xs:complexType>
                      </xs:element>
                      <xs:element name="name" minOccurs="0">
                          <xs:complexType>
                            <xs:sequence>
                              <xs:element name="string" type="xs:string" />
                            </xs:sequence>
                          </xs:complexType>
                      </xs:element>
                  </xs:all>
              </xs:complexType>
          </xs:element>
Otherwise (i.e. the object is a member of another object definition, thus has a name), the object definition transforms to the following XML schema element definition. Note $name represents the name of the object, and needs to be replaced by the actual name of the object.
            
<xs:element name="$name" xmlns:xs="http://www.w3.org/2001/XMLSchema">
              <xs:complexType>
                  <xs:sequence>
                  <!--Until the next comment, it is a copy of the previous example-->
                      <xs:element name="object">
                          <xs:complexType>
                              <xs:all>
                                  <xs:element name="id">
                                      <xs:complexType>
                                        <xs:sequence>
                                          <xs:element name="integer" type="xs:integer" />
                                        </xs:sequence>
                                      </xs:complexType>
                                  </xs:element>
                                  <xs:element name="name" minOccurs="0">
                                      <xs:complexType>
                                        <xs:sequence>
                                          <xs:element name="string" type="xs:string" />
                                        </xs:sequence>
                                      </xs:complexType>
                                  </xs:element>
                              </xs:all>
                          </xs:complexType>
                      </xs:element>
                  <!--Until here-->
                  </xs:sequence>
              </xs:complexType>
          </xs:element>

Array Schema to XML Schema

Shown below is an example Data Schema of an Array Schema. The array consists of exactly three number literals with each value within the value range of [ 0 ... 2047 ].
            {
                "type": "array",
                "items": {
                    "type": "number",
                    "minimum": 0,
                    "maximum": 2047
                },
                "minItems": 3,
                "maxItems": 3
            }
          
When the array is anonymous (i.e. it is the root, or participates in another array definition), the above array definition transforms to the following XML Schema element definition.
            
<xs:element name="array" xmlns:xs="http://www.w3.org/2001/XMLSchema">
      <xs:complexType>
          <xs:sequence>
              <xs:element name="double" minOccurs="3" maxOccurs="3">
                  <xs:simpleType name="minInclusive">
                      <xs:restriction base="xs:double">
                          <xs:minInclusive value="0"/>
                          <xs:maxInclusive value="2047"/>
                      </xs:restriction>
                  </xs:simpleType>
              </xs:element>
          </xs:sequence>
      </xs:complexType>
  </xs:element>
Otherwise (i.e. the array is a member of an object definition, thus has a name), the array definition transforms to the following XML schema element definition. Note $name represents the name of the array, and needs to be replaced by the actual name of the array.
            
<xs:element name="$name" xmlns:xs="http://www.w3.org/2001/XMLSchema">
      <xs:complexType>
          <xs:sequence>
          <!--Until the next comment, it is a copy of the previous example-->
              <xs:element name="array">
                  <xs:complexType>
                      <xs:sequence>
                          <xs:element name="double" minOccurs="3" maxOccurs="3" >
                              <xs:simpleType name="minInclusive">
                                  <xs:restriction base="xs:double">
                                      <xs:minInclusive value="0"/>
                                      <xs:maxInclusive value="2047"/>
                                  </xs:restriction>
                              </xs:simpleType>
                          </xs:element>
                      </xs:sequence>
                  </xs:complexType>
              </xs:element>
          <!--Until here-->
          </xs:sequence>
      </xs:complexType>
  </xs:element>