XML documents can have a reference to a DTD or an XML Schema.
A Simple XML Document
Look at this simple XML document called "note.xml":
<?xml version="1.0"?>
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
A Simple DTD
This is a simple DTD file called "note.dtd" that
defines the elements of the XML document above ("note.xml"):
<!ELEMENT note (to, from, heading, body)>
<!ELEMENT to (#PCDATA)>
<!ELEMENT from (#PCDATA)>
<!ELEMENT heading (#PCDATA)>
<!ELEMENT body (#PCDATA)>
Line 1 defines the note element to have four elements:
"to, from, heading, body". Line 2-5 defines the to element to be of the type
"#PCDATA", the from element to be of the type
"#PCDATA", and so on...
A Simple XML Schema
This is a simple XML Schema file called "note.xsd" that defines the elements of the XML
document
above ("note.xml"):
The note element is said to be of a complex type because it contains other elements.
The other elements (to, from, heading, body) are said to be simple types because they do
not contain other elements. You will learn more about simple and complex types
in the following chapters.
A Reference to a DTD
This XML document has a reference to a DTD:
<?xml version="1.0"?>
<!DOCTYPE note SYSTEM
"http://www.w3schools.com/dtd/note.dtd">
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
A Reference to an XML Schema
This XML document has a reference to an XML Schema:
<?xml version="1.0"?>
<note
xmlns="http://www.w3schools.com"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=
"http://www.w3schools.com/schema/note.xsd">
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
W3Schools is for training only. We do not warrant its correctness or its fitness for use.
The risk of using it remains entirely with the user. While using this site, you agree to have read and accepted our
terms of use and
privacy policy.