17.06.2013 Views

Beginning Microsoft SQL Server 2008 ... - S3 Tech Training

Beginning Microsoft SQL Server 2008 ... - S3 Tech Training

Beginning Microsoft SQL Server 2008 ... - S3 Tech Training

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 16: A Brief XML Primer<br />

❑ Tags cannot straddle other tags.<br />

❑ You can’t use restricted characters for anything other than what they indicate to the XML parser.<br />

If you need to represent any of these special characters, then you need to use an escape sequence<br />

(which will be translated back to the character you requested).<br />

It’s worth noting that HTML documents are more consistently “well formed” than in years past.<br />

Around the time that XML came out, a specification for XHTML was also developed — that is, HTML<br />

that is also valid XML. Many developers today try and make their HTML meet XHTML standards<br />

with the result being, at the least, much more well formed HTML.<br />

The following is an example of a document that is well formed:<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

Notice that we didn’t need to have a closing tag at all for the declaration. That’s because the declaration<br />

is a preprocessor directive — not an element. Essentially, it is telling the XML parser some things it<br />

needs to know before the parser can get down to the real business of dealing with our XML.<br />

So, this has been an extremely abbreviated version of what’s required for your XML document to be considered<br />

to be well formed, but it pretty much covers the basics for the limited scope of our XML coverage<br />

in this book.<br />

Understanding these concepts is going to be absolutely vital to your survival (well, comprehension at<br />

least) in the rest of the chapter. The example that is covered next should reinforce things for you, but, if<br />

after looking at the XML example, you find you’re still confused, then read the preceding text again or<br />

check out Professional XML or some other XML book. Your sanity depends on knowing this stuff before<br />

you move on to the styling and schema issues at the end of the chapter.<br />

An XML Example<br />

480<br />

OK — if there’s one continuing theme throughout this book, it’s got to be that I don’t like explaining<br />

things without tossing out an example or two. As I’ve said earlier, this isn’t an XML book, so I’m not<br />

going to get carried away with my examples here, but let’s at least take a look at what we’re talking<br />

about.<br />

Throughout the remainder of this chapter, you’re going to find that life is an awful lot easier if you have<br />

some sort of XML editing tool (<strong>Microsoft</strong> offers a free one called XML Notepad. I’ve tended toward a<br />

product called XMLSpy, which was one of the earliest full function XML editors). Because XML is text<br />

based, you can easily open and edit XML documents in Notepad — the problem is that you’re not going<br />

to get any error checking. How are you going to know that your document is well formed? Sure, you can<br />

look it over if it’s just a few lines, but get to a complete document or a style sheet document (we will discuss<br />

transformations later in the chapter), and life will quickly become very difficult.

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

Saved successfully!

Ooh no, something went wrong!