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.

the scope of any particular XML document. So, what’s all the confusion about? Well, it usually falls into<br />

two camps: Those that don’t know they need to have a singular root node (which you now know), and<br />

those who don’t understand how root nodes are named (which you will understand in a moment).<br />

Because the general statement is usually “You must have a root node,” people usually interpret that to<br />

mean that they must have a node that is called root. Indeed, you’ll occasionally find XML documents<br />

that do have a root node named Root (or root or ROOT). The reality, however, is that root nodes follow<br />

the exact same naming scheme as any other element with only one exception — the name must be unique<br />

throughout the document. That is, no other element in the entire document can have the same name as<br />

the root.<br />

Attributes<br />

Attributes exist only within the context of an element. They are implemented as a way of further describing<br />

an element, and are placed within the boundaries of the opening tag for the element:<br />

<br />

Optionally, some other XML<br />

<br />

Regardless of the data type of the information in the value for the attribute, the value must be enclosed<br />

in either single or double quotes.<br />

By default, XML documents have no concept of data type. We will investigate ways of describing the<br />

rules of individual document applications later in this chapter. At that time, we’ll see that there are<br />

some ways of ensuring data type — it’s just that you set the rules for it; XML does not do that by itself.<br />

No Defects — Being Well Formed<br />

The part of the rules that define how XML must look — that is, what elements are okay, how they are<br />

defined, what parts they have — is about whether an XML document is well formed or not.<br />

Actually, all SGML-based languages have something of the concept of being well formed. Heck, even<br />

HTML has something of the concept of being well formed — it’s just that it has been largely lost in the<br />

fact that HTML is naturally more forgiving and that browsers ignore many errors.<br />

If you’re used to HTML at all, then you’ve seen some pretty sloppy stuff as far as a tag-based language<br />

goes. XML has much stricter rules about what is and isn’t OK. The short rendition looks like this:<br />

❑ Every XML document must have a unique “root” node.<br />

Chapter 16: A Brief XML Primer<br />

The existence of a root node is a key difference between an XML document and an<br />

XML fragment. Often, when extracting things from <strong>SQL</strong> <strong>Server</strong>, you’ll be extracting<br />

little pieces of XML that belong to a large whole. We refer to these as XML fragments.<br />

Because an XML fragment is not supposed to be the whole document, we<br />

don’t expect these to have a root node.<br />

❑ Every tag must have a matching (case sensitive) closing tag unless the opening tag is self-closing.<br />

479

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

Saved successfully!

Ooh no, something went wrong!