A Simple XML Document

If you’re new to XML or just need to identify a feature you haven’t seen before, looking at a sample document may be helpful. The document shown in Example 1-1 contains a variety of XML features.

Example 1-1. A simple XML document
1  <?xml version="1.0" encoding="UTF-8" standalone="no" ?>
2  <?xml-stylesheet href="mine.css" type="text/css" ?>
3  <!--This is a very simple document.-->
4  <!DOCTYPE message SYSTEM "myMessage.dtd" >
5  <message xmlns="http://simonstl.com/ns/examples/message"
6              xmlns:xsi="http://www.w3.org/2001/XMLSchema-
               instance"
7              xsi:schemaLocation="message.xsd"
8              xml:lang="en" date="2005-10-06" >
9        This is a message!
10  </message>

This document contains many common XML structures, each of which is described briefly here and in greater detail later in this book. Line 1 is an optional XML declaration that provides version and encoding information, plus a declaration that indicates whether or not the document stands alone (i.e., whether it relies on external markup declarations). Line 2 is a processing instruction—more precisely, an XML stylesheet processing instruction that references a local CSS stylesheet. Line 3 is a comment and line 4 is a document type declaration (or DOCTYPE declaration) that points to a document type definition, or DTD. A DTD contains rules for document validation. The message element start-tag, on line 5, is the root (or document) element. This element contains several attributes with varying purposes. The attribute on line 5 ...

Get XML Pocket Reference, 3rd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.