29.01.2013 Views

WebSphere Application Server - IBM Redbooks

WebSphere Application Server - IBM Redbooks

WebSphere Application Server - IBM Redbooks

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.

10.1.2 Well-formed XML documents<br />

Although XML does not have any predefined tags, there are certain rules that<br />

each XML document has to follow in order to be well formed. By definition, if a<br />

document is not well formed, it is not XML. The rules are:<br />

► Tags cannot be inferred; they must be explicit.<br />

► A document must contain one root element.<br />

► All beginning tags and ending tags match up.<br />

► Empty tags must end with />.<br />

► Tags must nest correctly.<br />

► An entity cannot contain a reference to itself.<br />

► Entities must be declared before they are used.<br />

► Element names are case sensitive.<br />

► All attribute values must be enclosed in single or double quotation marks.<br />

► No attribute may appear more than once on the same start tag or empty tag.<br />

Note: Similar rules exist for HTML; the XHTML specification defines them.<br />

However, HTML browsers also accept HTML documents that are not well<br />

formed.<br />

10.1.3 Document type definitions (DTDs)<br />

Well-formed documents offer many of the advantages of XML, such as<br />

extensibility and adding structure to a set of data. However, exchanging<br />

information through XML documents requires additional functionality: It must be<br />

possible to build a common grammar for a set of documents and to check<br />

compliance automatically.<br />

Document type definitions (DTDs) address these needs. A DTD defines:<br />

► The allowed sequence and nesting of tags<br />

► Elements and their attributes including multiplicity<br />

► Attribute values and their types and defaults<br />

► Entities and notation<br />

DTDs express meta-information about a document's content. With a DTD, an<br />

XML parser can verify the DTD compliance of an XML document. A DTD can be<br />

used in one or more XML documents.<br />

Document types can be declared externally:<br />

<br />

Or internally:<br />

<br />

Chapter 10. Working with XML 313

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

Saved successfully!

Ooh no, something went wrong!