XML Schemas & DTDs

XML are validated with a DTD or with an XML Schema.

Document Type Definition (DTD) defines the legal elements of an XML Document.

<!DOCTYPE note SYSTEM “external.dtd”>
<root>

XML Schema is an XML-based alternativ to DTD.

<root
xmlns=http://mysite
xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance”
xsi:schemaLocation=”http://mysite/schema.xsd”>

Schemas will in the near future replace DTDs.

DTD Example – External DTD file

<?xml version=”1.0″?>
<!ELEMENT root (child)>
<!ELEMENT child (#PCDATA)>

DTD Example – Using DTD in a XML

<?xml version=”1.0″ encoding=”utf-8″ ?>
<!DOCTYPE note SYSTEM “external.dtd”>
<root>
…..<child>123456</child>
</root>

Schema Example

<?xml version=”1.0″ encoding=”UTF-8″?>
<xs:schema xmlns:xs=”http://www.w3.org/2001/XMLSchema”
xmlns=”www.mysite.dk”
xmlns:wmh=””
elementFormDefault=”qualified”
targetNamespace=”www.mysite.dk”>
<xs:element name=”root”>
…..<xs:complexType>
……….<xs:sequence>
……………<xs:element ref=”child”/>
……….</xs:sequence>
…..</xs:complexType>
</xs:element>
<xs:element name=”child” type=”xs:string”/>
</xs:schema>

Schema Example – Using Schema in a XML

<?xml version=”1.0″ encoding=”utf-8″?>
<root xmlns=”www.mysite.dk”
xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance”
xsi:schemaLocation=”www.mysite.dk ex.xsd”>
…..<child/>
</root>

You can leave a response, or trackback from your own site.

Leave a Reply


one × 4 =