XML Document Syntax
If you are familiar with HTML, a simple XML document shouldn’t be too difficult to understand.
<?xml version "1.0" standalone="no"?> <!DOCTYPE accounts SYSTEM "simple.dtd"> <accounts> <customer> <name>Bobby Five</name> <accountNumber>4456</accountNumber> <balance>111.32</balance> </customer> </accounts>
In the first line, the code between the <?xml
and the ?> is called an XML
declaration
.
This declaration contains special information for the XML processor
(the program reading the XML) indicating that this document conforms
to Version 1.0 of the XML standard. In addition, the
standalone=
"
no
"
attribute informs the program that an outside DTD is needed to
correctly interpret the document.
The second line is the
DOCTYPE
declaration. It identifies the root
element
(accounts in our
example) and the DTD for the document. The root element is the
element in the document that contains all other elements. It must be
unique, which means it may be used only once in the document. All XML
documents must have a root element. The root
element in HTML and XHTML documents is html, since
the whole document is contained within
<html> tags.
The last part of the declaration is a pointer to the DTD itself. The
SYSTEM identifier points to the DTD resource by
location (its URL). In our example, the DTD of the document resides
in a separate local file named simple.dtd. As an
alternative, some declarations use the PUBLIC identifier to point to the DTD (or other resource) by a unique ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access