Web Technologies - Old Questions
8. How to represent data types in XML schema? Explain.
One of the greatest strength of XML Schemas is the support for data types. Using XML schema it is easier to describe allowable document content; it is easier to validate the correctness of data; it is easier to convert data between different data types.
Built in data types supported by XML schema:
XML Schema has a lot of built-in data types. The most common types are:
xs:string
xs:decimal
xs:integer
xs:boolean
xs:date
xs:time
XML schema defines in the namespace http://www.w3.org/2001/XMLschema that contains built in data types. There are two classes of XML schema data types:
Complex type is a data type is represented using markup.
Simple type is a data type whose values are represented in XML doc by character data. XML markup such as <types> is known as XML schema that conforms to W3C defined XML schema vocabulary which defines all or part of the vocabulary for another XML document. The <schema> is the root element for any XML schema document. The child elements of schema define the data types.
Example for writing a simple XML Schema:
<?xml version=”1.0”?>
<xs:schema xmlns:xs=” http://www.w3.org/2001/XMLSchma”>
<xs:element name=”student” >
<xs:complexType>
<xs:sequence>
<xs:element name=”name” value=”xs:string” />
<xs:element name=”regno” value=”xs:string” />
<xs:element name=”dept” value=”xs:string” />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>