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.

As a side note, you can perform a rather quick and dirty check to see whether your XML is well formed<br />

or not by opening the document in <strong>Microsoft</strong>’s Internet Explorer — it will complain to you if the document<br />

is not well formed.<br />

For this example, we’re going to look at an XML representation of what some of our AdventureWorks<strong>2008</strong><br />

data might look like. In this case, I’m going to take a look at some order information. We’re going to start<br />

with just a few things and grow from there.<br />

First, we know that we need a root node for any XML document that we’re going to have. The root node<br />

can be called anything we want, as long as it is unique within our document. A common way of dealing<br />

with this is to call the root root. Another common example would be to call it something representative<br />

of what the particular XML document is all about.<br />

For our purposes, we’ll start off with something hyper-simple, and just use root:<br />

<br />

<br />

Just that quickly we’ve created our first well-formed XML document. Notice that it didn’t include the<br />

tag that we saw in the earlier illustration. We could have put that in, but it’s actually an optional<br />

item. The only restriction related to it is that, if you include it, it must be first. For best practice reasons as<br />

well as clearness, we’ll go ahead and add it:<br />

<br />

<br />

<br />

Actually, by the rules of XML, any tag starting with is considered to be a reserved tag — that is,<br />

you shouldn’t name your tags that, as they are reserved for current or future use of the W3C as XML<br />

goes into future versions.<br />

So, moving on, we have our first well-formed XML document. Unfortunately, this document is about as<br />

plain as it can get — it doesn’t really tell us anything. Well, for our example, we’re working on describing<br />

order information, so we might want to start putting in some information that is descriptive of an<br />

order. Let’s start with a SalesOrderHeader tag:<br />

<br />

<br />

<br />

<br />

OK — so this is getting monotonous — isn’t it? We now know that we have one order in our XML document,<br />

but we still don’t know anything about it. Let’s expand on it some by adding a few attributes:<br />

<br />

<br />

<br />

<br />

Chapter 16: A Brief XML Primer<br />

481

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

Saved successfully!

Ooh no, something went wrong!