Chapter 05: Instances and schemasΒΆ

Schema

<!--Definitive XML Schema by Priscilla Walmsley (c) 2012 Prentice Hall PTR -->
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
            targetNamespace="http://example.org/ord"
            xmlns="http://example.org/ord"
            xmlns:prod="http://example.org/prod">

  <xsd:annotation>
    <xsd:documentation>
      This example shows how xsi:schemaLocation can be used to pull together multiple schema documents.
      An import is used to show the dependence on the prod namespace, but no schema location
      is provided in the schema; this type of "dangling" reference to product is allowed.
      This example also exhibits xsi:nil and xsi:type.
    </xsd:documentation>
  </xsd:annotation>

  <xsd:import namespace="http://example.org/prod" schemaLocation="chapter05prod.xsd"/>

  <xsd:element name="order" type="OrderType"/>
  <xsd:complexType name="OrderType">
    <xsd:sequence>
      <xsd:element name="items" type="ItemsType"/>
    </xsd:sequence>
  </xsd:complexType>

  <xsd:complexType name="ItemsType">
    <xsd:sequence>
      <xsd:element ref="prod:product" maxOccurs="unbounded"/>
    </xsd:sequence>
  </xsd:complexType>


</xsd:schema>

XML Document

<ord:order xmlns:ord="http://example.org/ord"
           xmlns:prod="http://example.org/prod"
           xmlns:xsd="http://www.w3.org/2001/XMLSchema"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:schemaLocation="http://example.org/prod chapter05prod.xsd
                               http://example.org/ord chapter05.xsd">
  <items>
    <prod:product>
      <number xsi:type="xsd:short">557</number>
      <name>Short-Sleeved Linen Blouse</name>
      <size xsi:nil="true"></size>
    </prod:product>
  </items>
</ord:order>

xsData XML Document

<?xml version='1.0' encoding='UTF-8'?>
<ns0:order xmlns:ns0="http://example.org/ord" xmlns:ns1="http://example.org/prod" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <items>
    <ns1:product>
      <number>557</number>
      <name>Short-Sleeved Linen Blouse</name>
      <size xsi:nil="true"/>
    </ns1:product>
  </items>
</ns0:order>

xsData JSON

{
    "items": {
        "product": [
            {
                "number": 557,
                "name": "Short-Sleeved Linen Blouse",
                "size": {
                    "value": null,
                    "system": null
                }
            }
        ]
    }
}

Samples Source

Definitive XML Schema by Priscilla Walmsley (c) 2012 Prentice Hall PTR