XSD | DTD |
---|---|
Defines list, order, data types of elements and attributes. | Defines list, order of elements and attributes. |
Provides control over the elements and attributes used in XML documents. | It does not provide control over elements and attributes. |
XSD allows to create customized datatype. | DTD does not allow to create customized datatype. |
Syntax of XSD is similar to XML document. | Syntax of DTD is different from XML document. |
XSD allows to define restrictions on data. For example: Define the content in a document by using only integer data type. | DTD does not allows to define restrictions on data. |
<xsd:element name=“CARNAME” TYPE=“xsd:string”/>
<xsd:element name=“COMPANYNAME” TYPE=“xsd:string”/>
<xsd:element name=“PRICE” TYPE=“xsd:positiveInteger”/>
XML document with simple type elements and associated XSD using creation of custom data type.
<EMPLOYEENAME>Surabhi</EMPLOYEENAME>
<EMPLOYEEPHONE>9800000000</EMPLOYEEPHONE>
<xsd:element name=“EMPLOYEENAME” TYPE=“xsd:string”/>
<xsd:element name=“EMPLOYEEPHONE” TYPE=“xsd:string”/>
<xsd:simpleType name=“phoneno”>
<xsd:restriction base=“xsd:string”>
<xsd:length value=“15”/>
<xsd:pattern value=“\d{3}-\d{6}”/>
</xsd:restriction>
</xsd:simpleType>
Class | Method | Meaning |
---|---|---|
[0-9] | \ d | Any digit. |
[\ f\ r\ t \ n \ v] | \ s | Any white space. |
[A-Za-z0-9] | \ w | Any word character. |
[^0-9] | \ D | Not a digit. |
[^ \ f \ r \ t \ n\ v] | \ S | Not a White space. |
[^A-Za-z0-9] | \ W | Not a word character. |