Example XML document
Below is a very simple XML document that could be used to represent a book:
<?xml version="1.0" encoding="US-ASCII"?>
<book>
<title>The Fellowship of the Ring</title>
<author>J.R.R. Tolkien</author>
<copyright>1954 by J.R.R. Tolkien</copyright>
<text>The book’s content would go here.</text>
</book>
As you can see, XML data is organized by tags in a hierarchical, or nested, format. Tags are nested to show the relationship of the data: the title, author, copyright and text are all contained within the book.
The first line, which declares the XML document and the XML version, is required. Version 1.0 is currently the only accepted recommendation, and version 1.1 is a candidate for W3 recommendation. Most XML implementations use version 1.0. You can think of version 1.0 as released, while version 1.1 is only a release candidate. The encoding attribute is optional.
The next line declares the first element of the document, which is called the root element. An XML document can only contain one root element.
The remainder of the lines in the document contain child elements that are nested within the root element. In this example, the child elements only contain data, but they may contain child elements of their own.
Spaces and tabs in the document are ignored. You may use indentation to help improve readability and provide a visual representation of the relationship between the tags.
Was this helpful?