Breaking News

XML Schema Examples

Example 1: csitquestion address demo
 
Given below is the source code of XML file that is used by www.csitquestions.com to store the details of it’s associates :
 
<?xml version=”1.0″ encoding=”UTF-7″?>

<csitquestion xmlns=”https://csitquestions.com”
xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance”
xsi:schemaLocation=”simple_with_schema.xsd”>
<address>
     <name>Dharmendra Das</name>
     <age>20</age>
     <address_str>D 210</address_str>
     <city>New Delhi</city>
     <state>CG</state>
     <pin>110000</pin>
</address>
<address>
     <name>XYZ Kumar</name>
     <age>20</age>
     <address_str>b 66</address_str>
     <city>Noida </city>
     <state>UP</state>
     <pin>201301</pin>
</address>
<address>
     <name>Sam </name>
     <age>20</age>
     <address_str>Karmpura</address_str>
     <city>Noida </city>
     <state>UP</state>
     <pin>201301</pin>
</address>
<address>
     <name>AK Kumar</name>
     <age>20</age>
     <address_str>b 66</address_str>
     <city>Noida </city>
     <state>UP</state>
     <pin>201301</pin>
</address>
<address>
     <name>VJ</name>
     <age>20</age>
     <address_str>e 66</address_str>
     <city>New Delhi </city>
     <state>DLI</state>
     <pin>201301</pin>
</address>
<address>
     <name>Amu</name>
     <age>30</age>
     <address_str>J 3</address_str>
     <city>Noida </city>
     <state>UP</state>
     <pin>201301</pin>
</address>

</csitquestion>

 
Click here to view the file.
 
Schema declaration for above should look like this:
 
<?xml version=”1.0″ encoding=”UTF-7″?>
<xsd:schema xmlns:xsd=”http://www.w3.org/2001/XMLSchema”
targetNamespace=”https://csitquestions.com”
xmlns=”https://csitquestions.com”
elementFormDefault=”qualified”>
     <xsd:element name=”csitquestion”>
     <xsd:complexType>
     <xsd:sequence>
     <xsd:element ref=”address” minOccurs=”1″ maxOccurs=”unbounded”/>
     </xsd:sequence>
</xsd:complexType>
</xsd:element>
    <xsd:element name=”address”>
     <xsd:complexType>
     <xsd:sequence>
      <xsd:element ref=”name” minOccurs=”1″ maxOccurs=”1″/>
      <xsd:element ref=”age” minOccurs=”1″ maxOccurs=”1″ />
      <xsd:element ref=”address_str” minOccurs=”1″ maxOccurs=”1″/>
       <xsd:element ref=”city” minOccurs=”1″ maxOccurs=”1″/>
      <xsd:element ref=”state” minOccurs=”1″ maxOccurs=”1″/>
<xsd:element ref=”pin” minOccurs=”1″ maxOccurs=”1″ />
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name=”name” type=”xsd:string”/>
<xsd:element name=”age” type=”xsd:integer”>
<xsd:simpleType>
      <xsd:restriction base=”xsd:integer”>
      <xsd:minInclusive value=”16″ />
      <xsd:maxInclusive value=”75″ />
      </xsd:restriction>
</xsd:simpleType>
</xsd:element>
<xsd:element name=”address_str” type=”xsd:string”/>
<xsd:element name=”city” type=”xsd:string”/>
<xsd:element name=”state” type=”xsd:string”>
<xsd:simpleType>
      <xsd:restriction base=”xsd:string”>
      <xsd:minLength value=”2″ />
      <xsd:maxLength value=”4″ />
</xsd:restriction>
</xsd:simpleType>
</xsd:element>
<xsd:element name=”pin” type=”xsd:integer”>
<xsd:simpleType>
<xsd:restriction base=”xsd:integer”>
<xsd:length value=”6″ />
</xsd:restriction>
</xsd:simpleType>
</xsd:element> </xsd:schema>

Check Also

XML and Server

Generating XML with JSP   XML can be generated on a server without any installed …