02.06.2013 Views

XML Demystified

XML Demystified

XML Demystified

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.

CHAPTER 3 Document Type Defi nitions<br />

NJ<br />

07665<br />

<br />

<br />

555-555-1212<br />

555-555-5432<br />

555-555-7678<br />

555-555-9989<br />

<br />

bsmith@mycompany.com<br />

6970654<br />

<br />

<br />

External DTD are commonly used when <strong>XML</strong> documents are exchanged among<br />

business partners. Business partners agree to the structure of the DTD and then<br />

share the same external DTD for multiple <strong>XML</strong> documents.<br />

Typically one organization will be the “owner” of the DTD and is responsible for<br />

updating it and making it accessible to any partner that’s using it. The most common<br />

way to share a DTD is to make the source reference a URL. The DTD can be posted<br />

on a public web server so anybody using it can reference it. Even though one<br />

company or organization controls the DTD, they still need to agree on the content<br />

of the <strong>XML</strong> with their partners.<br />

In one sense, it’s good practice to use a DTD so that all parties using it agree and<br />

understand the exact structure of the document. Any change to the DTD needs to be<br />

clearly communicated. Another good reason to use a DTD is that the <strong>XML</strong> parsers<br />

can validate the structure of the document. There’s no need to write a lot of custom<br />

code for validation. The parser already has this built in to it. For example, if the<br />

parser comes across an element tag in the above document that has ,<br />

this tag isn’t defined in the DTD and the parser throws an error. There is no need to<br />

check for this in the application code; the parser checks it for you.<br />

Another feature in the parser is its ability to ignore certain types of white space.<br />

Oftentimes an <strong>XML</strong> document may be structured like this to make it more human<br />

readable:<br />

<br />

Joe<br />

Brown<br />

<br />

Technically there’s a text node between the tag and tag.<br />

The value (on a Windows platform) is three characters, which consist of a carriage<br />

return, line feed, and tab. These characters aren’t part of the content of the<br />

37

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

Saved successfully!

Ooh no, something went wrong!