DTD Disadvantages
- DTD becomes complicated due to limited operators provided.
- DTD does not support data types.
- DTD’s are phased out due to their time consuming & tedious approach.
XSD (Extensible Schema Document)
- A Schema to validate XML documents
- Supports data types unlike DTD
- Is XML based syntax.
- Allows you to create you own customized data types.
DTD (Document Type Defination)
File extension - .dtd
Doesn't support the data types
XML file
<?xml version="1.0" encoding="UTF-8"?>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE PRODUCTDETAILS SYSTEM "D:/Naga%20XML%20Samples/product.dtd">
<PRODUCT>
<PNAME>Toy</PNAME>
<PPRICE>www</PPRICE>
</PRODUCT>
</PRODUCTDETAILS>
------------------------------------------------------------------------
DTD for above XML file
DTD for above XML file
<!ELEMENT BOOKDETAILS (BOOK)>
<!ELEMENT BOOK (NAME, PRICE, DESCRIPTION, QTY)>
<!ELEMENT NAME (#PCDATA)>
<!ELEMENT PRICE (#PCDATA)>
<!ELEMENT DESCRIPTION (#PCDATA)>
<!ELEMENT QTY (#PCDATA)>
XSD (Extensible Schema Document))
File extention- .xsd
Allowed to create own data types.
Supports following Data Types
Supports following Data Types
- Simple Types
- Complex Types
- Sequence of Elements
<?xml version="1.0" encoding="UTF-8"?>
<PRODUCTDETAILS xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="D:/Naga%20XML%20Samples/product.xsd">
<PRODUCT>
<PNAME>Toy</PNAME>
<PPRICE>www</PPRICE>
</PRODUCT>
</PRODUCTDETAILS>
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" >
<xs:element name="PRODUCTDETAILS" type="pdet-type"></xs:element>
<xs:complexType name="pdet-type">
<xs:sequence>
<xs:element name="PRODUCT" type="prod-type" />
</xs:sequence>
</xs:complexType>
<xs:complexType name="prod-type">
<xs:sequence>
<xs:element name="PNAME" type="xs:string" />
<xs:element name="PPRICE" type="xs:int" />
</xs:sequence>
</xs:complexType>
</xs:schema>