Chapter 04: Schema compositionΒΆ

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 pulls together examples 4-3, 4-4 and 4-5, illustrating include, chameleon include,
      and import, respectively.  Note that only the root element of the instance is prefixed,
      because all elements in all schema documents are declared locally and no
      elementFormDefault is specified.
    </xsd:documentation>
  </xsd:annotation>

  <xsd:include schemaLocation="chapter04ord2.xsd"/>
  <xsd:include schemaLocation="chapter04cust.xsd"/>
  <xsd:import namespace="http://example.org/prod" schemaLocation="chapter04prod.xsd"/>

  <xsd:element name="order" type="OrderType"/>
  <xsd:complexType name="OrderType">
    <xsd:sequence>
      <xsd:element name="number" type="OrderNumType"/>
      <xsd:element name="customer" type="CustomerType"/>
      <xsd:element name="items" type="prod:ItemsType"/>
    </xsd:sequence>
  </xsd:complexType>

</xsd:schema>

XML Document

<ord:order  xmlns:ord="http://example.org/ord"
            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xsi:schemaLocation="http://example.org/ord chapter04.xsd">
  <number>123ABBCC123</number>
  <customer>
    <name>Priscilla Walmsley</name>
    <number>15466</number>
  </customer>
  <items>
    <product>
      <number>557</number>
      <name>Short-Sleeved Linen Blouse</name>
      <size system="US-DRESS">10</size>
      <color value="blue"/>
    </product>
  </items>
</ord:order>

xsData XML Document

<?xml version='1.0' encoding='UTF-8'?>
<ns0:order xmlns:ns0="http://example.org/ord">
  <number>123ABBCC123</number>
  <customer>
    <name>Priscilla Walmsley</name>
    <number>15466</number>
  </customer>
  <items>
    <product>
      <number>557</number>
      <name>Short-Sleeved Linen Blouse</name>
      <size system="US-DRESS">10</size>
      <color value="blue"/>
    </product>
  </items>
</ns0:order>

xsData JSON

{
    "number": "123ABBCC123",
    "customer": {
        "name": "Priscilla Walmsley",
        "number": 15466
    },
    "items": {
        "product": {
            "number": 557,
            "name": "Short-Sleeved Linen Blouse",
            "size": {
                "value": 10,
                "system": "US-DRESS"
            },
            "color": {
                "value": "blue"
            }
        }
    }
}

Samples Source

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