Database Reference
In-Depth Information
<states>
<controlinfo count="1"/>
<state name="Delaware">
<city>Dover</city>
<city>Wilmington</city>
</state>
</states>
The empty element, controlinfo , has one attribute, count , but no content. Note that it isn't
delimited by start and end tags but exists within an empty element tag (that starts with < and ends with
/> ).
An alternative syntax for empty elements, using start and end tags, is also valid:
<controlinfo count="1"></controlinfo>
Many programs that generate XML use this form.
Note Though it's easy to design XML documents, designing them well is as much a challenge as designing a
database. Many experienced XML designers disagree over the best use of attributes and even whether attributes
should be used at all (without attributes, empty elements have virtually no use). While elements may in some ways
map more ideally to relational data, this doesn't mean attributes have no place in XML design. After all, XML isn't
intended to (and in principle, can't) conform to the relational model of data. In fact, you'll see that a “pure”
element-only design can be more difficult to work with in T-SQL.
Understanding the XML Declaration
In addition to elements and attributes, XML documents can have other parts, but most of them are
important only if you really need to delve deeply into XML. Though it is optional, the XML declaration is
one part that should be included in an XML document to precisely conform to the W3C
recommendation. If used, it must occur before the root element in an XML document.
The XML declaration is similar in format to an element, but it has question marks immediately next
to the angle brackets. It always has an attribute named version ; currently, this has two possible values:
"1.0" and "1.1" . (A couple other attributes are defined but aren't required.) So, the simplest form of an
XML declaration is as follows:
<?xml version="1.0" ?>
XML has other aspects, but this is all you need to get started. In fact, this may be all you'll ever need
to be quite effective. As you'll see, we don't use any XML declarations (or even more important things
such as XML schemas and namespaces) for our XML documents, yet our small examples work well, are
representative of fundamental XML processing, and could be scaled up to much larger XML documents.
 
Search WWH ::




Custom Search