Beginning Microsoft SQL Server 2008 ... - S3 Tech Training
Beginning Microsoft SQL Server 2008 ... - S3 Tech Training Beginning Microsoft SQL Server 2008 ... - S3 Tech Training
Chapter 16: A Brief XML Primer So, with all that said, in this chapter we’ll look at: ❑ What XML is ❑ What other technologies are closely tied to XML I mentioned a bit ago that XML is usually not a good way to store data, but there are exceptions. One way that XML is being utilized for data storage is for archival purposes. XML compresses very well, and it is in a very open kind of format that will be well understood for many years to come — if not forever. Compare that to, say, just taking a SQL Server 2008 backup. A decade from now when you need to restore some old data to review archival information, you may very well not have a SQL Server installation that can handle such an old backup file, but odds are very strong indeed that you’ll have something around that can both decompress (assuming you used a mainstream compression library such as ZIP) and read your data. Very handy for such “deep” archives. XML Basics 474 There are tons and tons of books out there on XML (for example, Wrox’s Professional XML, by Evjen et al). Given how full this book already is, my first inclination was to shy away from adding too much information about XML itself, and assume that you already knew something about XML. I have, however, come to realize that even all these years after XML hit the mainstream, I continue to know an awful lot of database people who think that XML “is just some Web technology,” and, therefore, have spent zero time on it — they couldn’t be more wrong. XML is first and foremost an information technology. It is not a Web-specific technology at all. Instead, it just tends to be thought of that way (usually by people who don’t understand XML) for several reasons — such as: ❑ XML is a markup language, and looks a heck of a lot like HTML to the untrained eye. ❑ XML is often easily transformed into HTML. As such, it has become a popular way to keep the information part of a page, with a final transformation into HTML only on request — a separate transformation can take place based on criteria (such as what browser is asking for the information). ❑ One of the first widely used products to support XML was Microsoft’s Internet Explorer. ❑ The Internet is quite often used as a way to exchange information, and that’s something that XML is ideally suited for. Like HTML, XML is a text-based markup language. Indeed, they are both derived from the same original language, called SGML. SGML has been around for much longer than the Internet (at least what we think of as the Internet today), and is most often used in the printing industry or in government related documentation. Simply put, the “S” in SGML doesn’t stand for simple (for the curious, SGML stands for “standard generalized markup language”) — SGML is anything but intuitive and is actually a downright pain to learn. (I can only read about 35 percent of SGML documents that I’ve seen. I have, however, been able to achieve a full 100 percent nausea rate when reading any SGML.) XML, on the other hand, tends to be reasonably easy to decipher.
So, this might have you asking the question: “Great — where can I get a listing of XML tags?” Well, you can’t — at least, not in the sense that you’re thinking when you ask the question. XML has very few tags that are actually part of the language. Instead, it provides ways of defining your own tags and utilizing tags defined by others (such as the industry groups I mentioned earlier in the chapter). XML is largely about flexibility — which includes the ability for you to set your own rules for your XML through the use of either an XML schema document or the older Document Type Definition (DTD). An XML document has very few rules placed on it just because it happens to be XML. The biggie is that it must be what is called well formed. We’ll look into what well formed means shortly. Now, just because an XML document meets the criteria of being well formed doesn’t mean that it would be classified as being valid. Valid XML must not only be well formed, but must also live up to any restrictions placed on the XML document by XML schemas or DTDs that document references. We will briefly examine DTDs and XML schemas later on in this chapter. XML can also be transformed. The short rendition of what this means is that it is relatively easy for you to turn XML into a completely different XML representation or even a non-XML format. One of the most common uses for this is to transform XML into HTML for rendering on the Web. The need for this transformation presents us with our first mini-opportunity to compare and contrast HTML with XML. In the simplest terms, XML is about information, and HTML is about presentation. The information stored in XML is denoted through the use of what are called elements and attributes. Elements are usually created through the use of an opening and a closing tag (there’s an exception, but we’ll see that later) and are identified with a case-sensitive name (no spaces allowed). Attributes are items that further describe elements and are embedded in the element’s start tag. Attribute values must be in matched single or double quotes. Parts of an XML Document Well, a few of the names have already flown by, but it makes sense, before we get too deep into things, to stop and create something of a glossary of terms that we’re going to be utilizing while talking about XML documents. What we’re really going to be doing here is providing a listing of all the major parts of an XML document that you will run into, as shown in Figure 16-1. Many of the parts of the document are optional, though a few are not. In some cases, having one thing means that you have to have another. In other cases, the parts of the document are relatively independent of each other. We will take things in something of a hierarchical approach (things that belong “inside” of something will be listed after whatever they belong inside of), and where it makes sense, in the order you’ll come across them in a given XML document. The Document Chapter 16: A Brief XML Primer The document encompasses everything from the very first character to the last. When we refer to an XML document, we are referring to both the structure and the content of that particular XML document. 475
- Page 461 and 462: So, as you can see, we can actually
- Page 463 and 464: Despite being schema-bound, this on
- Page 465 and 466: 14 Transactions and Locks This is o
- Page 467 and 468: we are unable or do not want to com
- Page 469 and 470: Figure 14-1 Data needed Data in cac
- Page 471 and 472: Transaction 4 This transaction wasn
- Page 473 and 474: Oops — problem!!! Transaction 2 h
- Page 475 and 476: The only cure for this is setting y
- Page 477 and 478: Exclusive Locks Exclusive locks are
- Page 479 and 480: Also: ❑ The Sch-S is compatible w
- Page 481 and 482: The syntax for switching between th
- Page 483 and 484: As with most things in life, howeve
- Page 485 and 486: purchased. Process 2 records sales;
- Page 487: Chapter 14: Transactions and Locks
- Page 490 and 491: Chapter 15: Triggers the world’s
- Page 492 and 493: Chapter 15: Triggers WITH ENCRYPTIO
- Page 494 and 495: Chapter 15: Triggers FOR|AFTER The
- Page 496 and 497: Chapter 15: Triggers 458 To illustr
- Page 498 and 499: Chapter 15: Triggers 460 IF EXISTS
- Page 500 and 501: Chapter 15: Triggers ❑ Feeding de
- Page 502 and 503: Chapter 15: Triggers Trigger Firing
- Page 504 and 505: Chapter 15: Triggers Like regular t
- Page 506 and 507: Chapter 15: Triggers The COLUMNS_UP
- Page 508 and 509: Chapter 15: Triggers This is the sa
- Page 510 and 511: Chapter 15: Triggers 472 we have th
- Page 514 and 515: Chapter 16: A Brief XML Primer Figu
- Page 516 and 517: Chapter 16: A Brief XML Primer Elem
- Page 518 and 519: Chapter 16: A Brief XML Primer ❑
- Page 520 and 521: Chapter 16: A Brief XML Primer 482
- Page 522 and 523: Chapter 16: A Brief XML Primer Name
- Page 524 and 525: Chapter 16: A Brief XML Primer The
- Page 526 and 527: Chapter 16: A Brief XML Primer 2. W
- Page 528 and 529: Chapter 16: A Brief XML Primer SQL
- Page 530 and 531: Chapter 16: A Brief XML Primer So,
- Page 532 and 533: Chapter 16: A Brief XML Primer If,
- Page 534 and 535: Chapter 16: A Brief XML Primer 496
- Page 536 and 537: Chapter 16: A Brief XML Primer Note
- Page 538 and 539: Chapter 16: A Brief XML Primer RAW
- Page 540 and 541: Chapter 16: A Brief XML Primer AUTO
- Page 542 and 543: Chapter 16: A Brief XML Primer EXPL
- Page 544 and 545: Chapter 16: A Brief XML Primer Chec
- Page 546 and 547: Chapter 16: A Brief XML Primer 508
- Page 548 and 549: Chapter 16: A Brief XML Primer 510
- Page 550 and 551: Chapter 16: A Brief XML Primer 512
- Page 552 and 553: Chapter 16: A Brief XML Primer The
- Page 554 and 555: Chapter 16: A Brief XML Primer 516
- Page 556 and 557: Chapter 17: Reporting for Duty, Sir
- Page 558 and 559: Chapter 17: Reporting for Duty, Sir
- Page 560 and 561: Chapter 17: Reporting for Duty, Sir
So, this might have you asking the question: “Great — where can I get a listing of XML tags?” Well,<br />
you can’t — at least, not in the sense that you’re thinking when you ask the question. XML has very<br />
few tags that are actually part of the language. Instead, it provides ways of defining your own tags<br />
and utilizing tags defined by others (such as the industry groups I mentioned earlier in the chapter).<br />
XML is largely about flexibility — which includes the ability for you to set your own rules for<br />
your XML through the use of either an XML schema document or the older Document Type Definition<br />
(DTD).<br />
An XML document has very few rules placed on it just because it happens to be XML. The biggie is that<br />
it must be what is called well formed. We’ll look into what well formed means shortly. Now, just because<br />
an XML document meets the criteria of being well formed doesn’t mean that it would be classified as<br />
being valid. Valid XML must not only be well formed, but must also live up to any restrictions placed on<br />
the XML document by XML schemas or DTDs that document references. We will briefly examine DTDs<br />
and XML schemas later on in this chapter.<br />
XML can also be transformed. The short rendition of what this means is that it is relatively easy for you<br />
to turn XML into a completely different XML representation or even a non-XML format. One of the most<br />
common uses for this is to transform XML into HTML for rendering on the Web. The need for this transformation<br />
presents us with our first mini-opportunity to compare and contrast HTML with XML. In the<br />
simplest terms, XML is about information, and HTML is about presentation.<br />
The information stored in XML is denoted through the use of what are called elements and attributes.<br />
Elements are usually created through the use of an opening and a closing tag (there’s an exception, but<br />
we’ll see that later) and are identified with a case-sensitive name (no spaces allowed). Attributes are<br />
items that further describe elements and are embedded in the element’s start tag. Attribute values must<br />
be in matched single or double quotes.<br />
Parts of an XML Document<br />
Well, a few of the names have already flown by, but it makes sense, before we get too deep into things,<br />
to stop and create something of a glossary of terms that we’re going to be utilizing while talking about<br />
XML documents.<br />
What we’re really going to be doing here is providing a listing of all the major parts of an XML document<br />
that you will run into, as shown in Figure 16-1. Many of the parts of the document are optional,<br />
though a few are not. In some cases, having one thing means that you have to have another. In other<br />
cases, the parts of the document are relatively independent of each other.<br />
We will take things in something of a hierarchical approach (things that belong “inside” of something<br />
will be listed after whatever they belong inside of), and where it makes sense, in the order you’ll come<br />
across them in a given XML document.<br />
The Document<br />
Chapter 16: A Brief XML Primer<br />
The document encompasses everything from the very first character to the last. When we refer to an<br />
XML document, we are referring to both the structure and the content of that particular XML document.<br />
475