Tuesday, 19 March 2013

New to XML schema

0
Report Abuse Add to Bookmarks Share
  • XML : Extensible Markup Language.
  • It is used for structure store and Transport information.
Example of simple Xml Schema:
  • XML Schema is an XML document defintion.
  • Definiting the XML document and its elements is an XML Schema.
simple.xsd:
<?xml version=”1.0″ encoding=”UTF-8″?>
<xs:schema xmlns:xs=”http://www.w3.org/2001/XMLSchema“>
<xs:element name=”student”>
<xs:complexType>
<xs:sequence>
 <xs:element name=”firstname” type=”xs:string”>
 <xs:element name=”secondname” type=”xs:string”>
</xs:sequence>
</xs:complexType>
<xs:element>
</xs:schema>
Here,
  • xmlns is namespace,
  • xs is xml schema.
simple.xml:
<?xml version=”1.0″ encoding=”UTF-8″?>
<student xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance” xsi:noNamespaceSchemaLocation=”simple.xsd”>
<firstname>sai</firstname>
<secondname>sri</secondname>
</student>
Thus an simple example of an XML Schema basic.
Hi friends if you are new to XML Schema..you dont know about XML Schema dont worry you can use the XML Viewer Tool which automatically generate the XML and also XML Schema.
XML Schema for the web site,
 first know about the elements included in a hierarchal format,by using that elements and XML Viewer we can create XML Schema.
Example :
OMTreeXmlSchema.xsd(xml schema defintion):
<item>
 <url>http://www.example.com</url>
 <title>Example Root</title>
<entitytype>5</entitytype>
 <owner>INTLOCK\Sigalit</owner>
 <version>1</version>
<template>Site</template>
<created>01/01/2007 00:00:00</created>
<modified>08/01/2007 10:37:35</modified>
 <items>
<item>
 <url>http://www.example.com/Item1.aspx</url>
 <title>Item1</title>
 <entitytype>9</entitytype>
<owner>INTLOCK\Sigalit</owner>
 <version>1</version>
 <template>Web Page</template>
<created>01/01/2007 00:00:00</created>
 <modified>08/01/2007 10:59:16</modified>
 <items />
</item>
 </items>
 </item>
OMTreeXmlSchema.xml
<?xml version=”1.0″ encoding=”UTF-8″?>
<xs:schema id=”OMTreeXmlSchema” elementFormDefault=”qualified”
xmlns:mstns=”OMTreeXmlSchema.xsd”
xmlns:xs=”http://www.w3.org/2001/XMLSchema“>
<xs:element name=”tree”>
 <xs:complexType>
<xs:sequence>
<xs:element name=”item” type=”XmlNode” />
</xs:sequence>
</xs:complexType>
</xs:element>
 <xs:complexType name=”XmlNode”>
<xs:all>
 <xs:element name=”url” type=”xs:string” />
<xs:element name=”title” type=”xs:string” />
<xs:element name=”entitytype” type=”xs:string” minOccurs=”0″ maxOccurs=”1″ />
<xs:element name=”owner” type=”xs:string” minOccurs=”0″ maxOccurs=”1″ />
<xs:element name=”version”  type=”xs:string” minOccurs=”0″ maxOccurs=”1″ />
<xs:element name=”template” type=”xs:string” minOccurs=”0″ maxOccurs=”1″ />
<xs:element name=”created”  type=”xs:string” minOccurs=”0″ maxOccurs=”1″ />
<xs:element name=”modified” type=”xs:string” minOccurs=”0″ maxOccurs=”1″ />
<xs:element name=”permissions” minOccurs=”0″ maxOccurs=”1″>
<xs:complexType>
<xs:sequence>
 <xs:element name=”user” type=”UserNode” minOccurs=”0″ maxOccurs=”unbounded”/>
<xs:element name=”group” type=”GroupNode” minOccurs=”0″ maxOccurs=”unbounded”/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name=”items” minOccurs=”0″ maxOccurs=”1″>
<xs:complexType>
 <xs:sequence>
 <xs:element name=”item” type=”XmlNode” minOccurs=”0″ maxOccurs=”unbounded” />
</xs:sequence>
 </xs:complexType>
</xs:element>
</xs:all>
</xs:complexType>
<xs:complexType name=”UserNode”>
<xs:sequence>
<xs:element name=”username” type=”xs:string” minOccurs=”1″ maxOccurs=”1″/>
<xs:element name=”permission” type=”PermissionEnum” minOccurs=”1″ maxOccurs=”1″/>
</xs:sequence>
</xs:complexType> <xs:complexType name=”GroupNode”>
 <xs:sequence>
<xs:element name=”groupname” type=”xs:string” minOccurs=”1″ maxOccurs=”1″/>
<xs:element name=”permission” type=”PermissionEnum” minOccurs=”1″ maxOccurs=”1″/>
</xs:sequence>
</xs:complexType> <xs:simpleType name=”PermissionEnum”>
<xs:restriction base=”xs:string”>
 <xs:enumeration value=”R”/>
<xs:enumeration value=”W”/>
</xs:restriction>
 </xs:simpleType>
</xs:schema>
check it out this XML Schema and run the
OMTreeXmlSchema.xml
You will get an XML Schema output.

No comments:

Post a Comment