An Introduction to XML - Example XML Documents and analysis (
Page 4 of 6 )
Example 1 - A well-formed XML document:
<?xml version="1.0" standalone="no"?>
<Mail>
<From>Author</From>
<To>Receiver</To>
<Date> Thu, 7 Oct 1999 11:15:16 -0600</Date>
<Subject>XML Introduction</Subject>
<body><p>Thanks for reading<Br/>
this article</p>
<br/>
<p>Hope you enjoyed this article</p>
</body>
</Mail>
The first line is the XML declaration and it identifies what follows as XML code.
It is called the prolog. The attribute version indicates the version of the XML
standard. The statement standalone="no" indicates that markup declarations are
external to the document. The XML declaration can be considered as a "processing
instruction". Though this declaration is not compulsory, it is better to include
such declaration. This will increase the portability of the document.
Example 2 - A valid XML document conforming to mail.dtd. Date element is missing because
it is optional in the mail DTD The element P has the attribute justify. After
the Body and before P Comments text is allowed, because DTD allows the use of
plain text in the Body element.
<?xml version="1.0" standalone="no"?>
<!DOCTYPE Mail system "http://infowest.com/DTDS/mail.dtd">
<Mail>
<From>Author</From>
<To>Receiver</To>
<Cc>Receiver2</Cc>
<Subject>XML Introduction</Subject>
<body>Comments:<p
align="justify">Thanks for reading<Br/>
this article</p>
<br/>
<p>Hope
you enjoyed this article</p>
</body>
</Mail>
Example 3 - A valid XML document conforming to "mail.dtd". Date element and Cc elements
are present The element P has the attribute right.
<?xml version="1.0" standalone="no"?>
<!DOCTYPE Mail system "http://infowest.com/DTDS/mail.dtd">
<Mail>
<From>Author</From>
<To>Receiver</To>
<Cc>Receiver2</Cc>
<Date> Thu, 7 Oct 1999
11:15:16 -0600</Date>
<Subject>XML Introduction</Subject>
<body>Comments:<p
align = "right" >Thanks for reading<Br/>
this article</p>
<br/>
<p>Hope
you enjoyed this article</p>
</body>
</Mail>
An XML document can have comments. XML's comment syntax is similar to that of
HTML. Any text, except double hyphen, "--", can be placed between <-- and -->
tags. Processing instruction(PI) can be embedded in the documents. The data components
of the PI should be recognized by the processing applications.
Publishers may want to include some codes that should not be parsed by the parsers.
Those codes can be put in to the ignored sections. An ignored section will have
the syntax like this:
<[CDATA[Any text to be ignored]]>
In simple words, any ignored sections start with <[CDATA[ and end with ]]>