Character Encodings in XML

The encoding declaration in the XML document identifies which encoding is used to represent the characters in the document. UTF-8 encoding allows the use of non-ASCII characters, regardless of the language of the user's operating system and browser or the language version of Office. When you use UFT-8 or UTF-16 character encoding, an encoding declaration is optional. XML parsers can determine automatically if a document uses UTF-8 or UTF-16 Unicode encoding.

Part V

The second line in the XML document is a dataroot element:

<dataroot xmlns:od="urn:schemas-rrricrosoft-com:officedata" xmlns:xsi=""

xsi:noNamespaceSchemaLocation="Shippers.xsd" generated="2004-10-17T22:12:53">

The dataroot element tag defines two namespaces:

xmlns:od="urn:schemas-microsoft-com:officedata" xmlns:xsi=""

A namespace is a collection of names in which each name is unique. The XML namespaces are used in XML documents to ensure that element names do not conflict with one another and are unique within a particular set of names (a namespace).

For example, the <TITLE> tag will certainly have a different meaning and content in an XML document generated from the Books table than the <TITLE> element used to describe the courtesy titles of your customers. If the two XML documents containing the <TITLE> tag were to be merged, there would be an element name conflict. Therefore, in order to distinguish between tags that have the same names but need to be processed differently, namespaces are used.

The attribute "xmlns" is an XML keyword for a namespace declaration. The namespace is identified by a Uniform Resource Identifier (URI) — either a Uniform Resource Locator (URL) or a Uniform Resource Name (URN). The URI used as an XML namespace name is simply an identifier; it is not guaranteed to point to anything. Most namespaces use URIs for the namespace names because URIs are guaranteed to be unique. The use of a namespace is identified via a name prefix. The prefix is mapped to a URI to select a namespace.

For example, in the context of the Shippers.xml document, the od prefix is associated with the "urn:schemas-microsoft-com:officedata" namespace and the xsi prefix identifies the "" namespace. These prefixes may be associated with other namespaces outside of this particular XML document.

Notice that the prefix is separated from the xmlns attribute with a colon and the URI is used as the value of the attribute.

In addition to namespaces, the dataroot element specifies where to find the schema. This is done by using two attributes: the location of a schema file that defines the rules of an XML document and the date the file was generated.

xsi:noNamespaceSchemaLocation="Shippers.xsd" generated="2004-10-17T22:12:53"

An XML document's data is contained in elements. An element consists of the following three parts:

Start tag — Contains the element's name (e.g., <ShipperID>) Element data — The representation of actual data (e.g., 1) End tag — Contains the element's name preceded by a slash (e.g., </ShipperID>)

Taking Your VBA Programming Skills to the Web

If you click on the minus sign in front of the data root element, you will notice that the dataroot element encloses all the elements in the Access XML file. Each element in a tree structure is called a node.

The dataroot node contains child nodes for each row of the Shippers table. Notice that the table name is used for each element representing a row. You can expand or collapse any row element by clicking on the plus/or minus sign (+/-) in front of the element tag name.

Within row elements, there is a separate element for each column (ShipperlD, CompanyName, and Phone). Notice that each XML element contains a start tag, the element data, and the end tag:


<ShipperID>1</ShipperID> <CompanyName>Speedy Express</CompanyName> <Phone>(503) 555-9831</Phone> </Shippers>

The ShipperlD, CompanyName, and Phone elements are children of the Shippers element. In turn, each Shippers element is a child of the dataroot element. XML documents can be nested to any depth as long as each inner node is entirely contained within the outer node.

3. Close the browser containing the Shippers.xml file.

0 0

Post a comment