Share this Page URL

Chapter 16. Working with XML Data in Access > Introducing XML - Pg. 565

Working with XML Data in Access 565 In this chapter, we'll describe the ways Access supports XML to store, transport, and present data. We will then show you how to export data to a simple XML datastore and demonstrate ways that datastore can be used within and outside of Access. From there, we'll move on to ways you can transform your XML data using XML stylesheets (the language used by the stylesheets to do this transformation is referred to as XSLT or XSL) to present your data. Toward the end of the chapter, you'll learn how to use Access to publish to a Web-ready format. Introducing XML There are a lot of good introductory books on XML, so we won't spend a lot of time on the ins and outs of the technology, but we will spend a brief time looking at the basic architecture. As mentioned, XML is primarily a structured markup language for data. HTML uses tags to tell a Web browser how to display textual elements. XML uses tags to tell a Web browser how to structure textual elements. Both use tags to tell a parsing engine what to do with the document, but the tags in XML are used to describe the relationship the elements in the document have to each other and to the whole. The tags in HTML describe how the content of the document should look (for the most part), regardless of how they're structured. What's a Parser? A parser is a subsystem of a program (like a spelling checker) that goes through a document and attempts to pick out patterns so that it can interpret them. An XML or HTML parser will look for patterns called tags , and when it encounters a tag, it treats the data between the start and end tags in a specific way. For example, in HTML, you could write the following line: <b> This is bold </b>. When an HTML parser encounters the <b> tag, it looks for a corresponding end tag, </b>, and working in conjunction with a rendering engine, will render (display) the text in boldface: This is bold. A Web browser is a good example of a program that contains various parsers. Most of XML's markup is designed to provide a flexible and extensible way to manage data elements such as the contents of a field--much to the same end as many database programs, including Access. That is, content developers use XML to provide a framework into which discrete data items can fit. For example, if you have a set of data that contains a repetitive structure--an address book, for example--and you want to abstract the structure and just plug in the values for each contact in that address book, you could use a database like Access or you could use XML, depending on the situation. Although XML isn't natively relational, like Access, there are some important similarities. As you've learned, Access stores data elements in tables and fields. In the Access world, the hier- archy goes as follows: tables are made up of fields; fields contain data. Data is then connected by way of relationships between field elements. XML "stores" data elements hierarchically as well. However, the hierarchy is accomplished using a tag set. Instead of tables that contain fields, an XML document uses a schema that defines which tags store other tags (similar to tables and fields) and which tags actually contain data elements (similar to fields and data). Consider the following XML document: <Table> <Field1>Hello</Field1> <Field2>World</Field2> </Table> In this XML document, the <Table> tag represents the top-level container into which another set of tags is placed. The <Table> tag does not contain data but contains tags that store data just like a table in Access. Within the <Table> tag are two <Field> tags that contain two data elements. As you can see, the structure of this XML file is self-describing, meaning that you can determine the rela- tionships between the elements simply by looking at the way the document is organized. If we were to translate this XML document into terms used to describe structures in Access, we would say that this database has a table named Table with two fields, Field1 and Field2, and one record containing the data elements "Hello" and "World" in the two fields.