How do we create the XSD schema?
- While creating XML documents, it is important to structure the elements such as name of the elements and datatypes which should be understood by application. Here the need of XSD Schema is sought.
- XSD schemas are the successors of DTD. The difference is that XSD itself uses a XML syntax. XSD schemas allows to declare the structure of your XML documents. This includes the inclusion of elements,attributes,mandatory and optional elements etc.
- The XML document now should conforms the XSD schema.
Example :<?xml version="1.0"?>
<xs:schema targetNamespace=http://myorganization.org/MySchema.xsd
xmlns=http://myorganization.org/MySchema.xsd
xmlns:xs="http://www.abc.org/2001/XMLSchema">
<xs:element name="Employees">
<xs:complexType>
<xs:choice minOccurs="1" maxOccurs="unbounded">
<xs:element name="Employee" type="EmployeeType"/>
</xs:choice>
</xs:complexType>
</xs:element>
<xs:complexType name="EmployeeType">
<xs:sequence>
<xs:element name="FirstName" type="xs:string" minOccurs="1" maxOccurs="1"/>
<xs:element name="LastName" type="xs:string" minOccurs="1" maxOccurs="1"/>
<xs:element name="Job" type="xs:string" minOccurs="1" maxOccurs="1"/>
<xs:element name="EmailAddress" type="xs:string" minOccurs="1" maxOccurs="1"/>
</xs:sequence>
<xs:attribute name="ID" form="unqualified" type="xs:string"/>
</xs:complexType>
</xs:schema>