Microsoft 9GD00001 Computer Accessories User Manual


 
Appendix A: Introduction to XML 405
The prefix is common for letting applications reading the document know that it is
indeed an XML document. The version is self-describing. Encoding is important because
it specifies the binary format of the text. If you have one application passing data to
another application, it’s important that both applications can read the document and are
using the same encoding. The utf-8 encoding is the default and for the purpose of this
book is the only encoding you will care about.
The angle brackets, < and >, define the markup in XML. For the file prefix, content is
placed between <? and ?> character sequences, but as the following sections show, most
other markup is different.
XML Elements
The XML elements in Listing A-1 are customer, name, and address. Each element is
defined by matching pairs of markup, following this pattern:
<elementName>value</elementName>
In the previous example, elementName is the name of the element and value is the data
associated with that element. Elements always have a begin tag and an end tag. Y
ou can
identify the end tag because it always follows the begin tag eventually (there may be other
element tags nested in between the pair) and contains a forward slash character before the
element name.
The value in the previous example can sometimes be blank, meaning there is no value
for that element. A value can also be one or more elements, such as customer, in Listing A-1,
which contains name and address elements. In Listing A-1, the value of name is Joe and the
value of address is 123 4th St. In addition to elements, you can have attributes, discussed next.
Attributes
An attribute decorates an element with a single value, such as in the following example:
<elementName attributeName="attributeValue">
elementValue
</elementName>
Notice that the attribute, attributeName, is inside of the start tag of the element. It
contains an equal sign and a quoted value. You can have multiple attributes on a single
element and they’ll be separated by spaces. Remember that attributes can have only one
value, but if you need to define more than one value, you must use elements.
Examples of attributes in Listing A-1 are version and encoding in the prefix and id
on customer.