05.05.2013 Views

Programming PHP

Programming PHP

Programming PHP

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

In HTML, you often have an open tag without a close tag. The most common example<br />

of this is:<br />

<br />

In XML, that is illegal. XML requires that every open tag be closed. For tags that<br />

don’t enclose anything, such as the line break , XML adds this syntax:<br />

<br />

Tags can be nested but cannot overlap. For example, this is valid:<br />

<strong>Programming</strong> <strong>PHP</strong><br />

but this is not valid, because the book and title tags overlap:<br />

<strong>Programming</strong> <strong>PHP</strong><br />

XML also requires that the document begin with a processing instruction that identifies<br />

the version of XML being used (and possibly other things, such as the text<br />

encoding used). For example:<br />

<br />

The final requirement of a well-formed XML document is that there be only one element<br />

at the top level of the file. For example, this is well formed:<br />

<br />

<br />

<strong>Programming</strong> <strong>PHP</strong><br />

<strong>Programming</strong> Perl<br />

<strong>Programming</strong> C#<br />

<br />

but this is not well formed, as there are three elements at the top level of the file:<br />

<br />

<strong>Programming</strong> <strong>PHP</strong><br />

<strong>Programming</strong> Perl<br />

<strong>Programming</strong> C#<br />

XML documents generally are not completely ad hoc. The specific tags, attributes,<br />

and entities in an XML document, and the rules governing how they nest, comprise<br />

the structure of the document. There are two ways to write down this structure: the<br />

Document Type Definition (DTD) and the Schema. DTDs and Schemas are used to<br />

validate documents; that is, to ensure that they follow the rules for their type of<br />

document.<br />

Most XML documents don’t include a DTD. Many identify the DTD as an external<br />

with a line that gives the name and location (file or URL) of the DTD:<br />

<br />

Sometimes it’s convenient to encapsulate one XML document in another. For example,<br />

an XML document representing a mail message might have an attachment element<br />

that surrounds an attached file. If the attached file is XML, it’s a nested XML<br />

This is the Title of the Book, eMatter Edition<br />

Copyright © 2002 O’Reilly & Associates, Inc. All rights reserved.<br />

Lightning Guide to XML | 263

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!