XML Basics (part 1) - Breaking It Down (Page 6 of 9 )
Every XML document must begin with a declaration that states the version of XML being used; this declaration is also referred to as the "document prolog."
<?xml version="1.0"?>
This document prolog may also contain additional information, such as the document
encoding, and whether the document is to be viewed in combination with external DTDs or other entities (as explained above, a DTD lays down the format for an XML document and can be used to verify whether or not it is valid.) Consequently, the document prolog can sometimes look like this,
<?xml version="1.0" standalone="yes" ?>
or this.
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
The document prolog also contains a document type declaration, used to specify
additional information about the document. This information typically includes the location of the DTD to use when validating the document (if there is one available), an optional list of entity declarations (more on this later), and the name of the root element of the document.
A document type declaration usually looks like this:
<!DOCTYPE rootElement DTDLocation
[
entityDeclarations
]
>
A possible document type declaration for the movie review above might look like
this:
<!DOCTYPE review SYSTEM "http://www.somedomain.com/review.dtd">
In this case, the document would be validated against the DTD located at http://www.somedomain.com/review.dtd
If entity declarations are present, this might be modified to read
<!DOCTYPE review SYSTEM "http://www.somedomain.com/review.dtd"
[
<!ENTITY
html "Hypertext Markup Language">
<!ENTITY xml "Extensible Markup Language">
]
>
Entities will be discussed in detail in the second part of this article.
This article copyright Melonfire 2001. All rights reserved.Next: Simply Element-ary >>
More XML Articles
More By icarus, (c) Melonfire