Skip to Content
XML Hacks
book

XML Hacks

by Michael Fitzgerald
July 2004
Intermediate to advanced
479 pages
12h 30m
English
O'Reilly Media, Inc.
Content preview from XML Hacks

Read an XML Document

Before you can do much with an XML document, you need to understand its basic parts. This hack explores the most common struchture found in XML

This hack lays the basic groundwork for XML: what it looks like and how it’s put together. Example 1-1 shows a simple document (start.xml) that contains some of the most common XML structures: an XML declaration, a comment, elements, attributes, an empty element, and a character reference. start.xml is well-formed, meaning that it conforms to the syntax rules in the XML specification. XML documents must be well-formed.

Example 1-1. start.xml

1. <?xml version="1.0" encoding="UTF-8"?>
2. 
3. <!-- a time instant -->
4. <time timezone="PST">
5. <hour>11</hour>
6. <minute>59</minute>
7. <second>59</second>
8. <meridiem>p.m.</meridiem>
9. <atomic signal="true" symbol="&#x25D1;"/>
10. </time>

The XML Declaration

The first line of the example contains an XML declaration, which is recommended by the XML spec but is not mandatory. If present, it must appear on the first line of the document. It is a human- and machine-readable flag that states a few facts about the content of the document.

Tip

An XML declaration is not a processing instruction, although it looks like one. Processing instructions are discussed in [Hack #3] .

In general, an XML declaration provides three pieces of information about the document that contains it: the XML version information; the character encoding in use; and whether the document stands alone or relies ...

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.
Start your free trial

You might also like

.NET & XML

.NET & XML

Niel M. Bornstein
XML Pocket Reference, 3rd Edition

XML Pocket Reference, 3rd Edition

Simon St. Laurent, Michael Fitzgerald

Publisher Resources

ISBN: 0596007116Supplemental ContentErrata Page