Learn XML Schema by Example: 1. Complex type

XML Schema development is one of the major requirements for the Web services. It is time to get rid of the RPC style and move to DOCUMENT style. First of this series I would like to start with complex type.

<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns="http://www.ojitha.org" targetNamespace="http://www.ojitha.org"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
  elementFormDefault="qualified" attributeFormDefault="unqualified">
  
     <xs:element name="process">
      <xs:complexType>
       <xs:sequence>
           <xs:element name="person" type="personType"/>
       </xs:sequence>
      </xs:complexType>
     </xs:element>
     
     <xs:complexType name="personType">
      <xs:sequence>
           <xs:element name="name" type="xs:string"/>
           <xs:element name="age" type="xs:integer"/>
      </xs:sequence>
     </xs:complexType>
 </xs:schema>

To understand the above schema, refer to the following

image

See the instance xml document

<?xml version="1.0" encoding="utf-8"?>
<process xmlns="http://www.ojitha.org"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="http://www.ojitha.org file:///C:/XmlPad%20Projects/first/po.xsd">
  <person>
    <name>Ojitha</name>
    <age>40</age>
  </person>
</process>

Above diagrams and xml code created in WMHelp XmlPad.

Comments

Popular posts from this blog

How To: GitHub projects in Spring Tool Suite

Spring 3 Part 7: Spring with Databases

Parse the namespace based XML using Python