Exploring XML and Access 2002

This content is no longer actively maintained. It is provided as is, for anyone who may still be using these technologies, with no warranties or claims of accuracy with regard to the most recent product version or service release.

Frank C. Rice
Microsoft Corporation

July 2001

Applies to:
Microsoft® Access 2002

Summary: Provides an overview of XML and the different ways of using it in Microsoft Access 2002, along with links to associated articles. (4 printed pages)

Contents

Introduction
XML Specifics
Access Specifics
XML and Data Access Pages
Programmatically Work with XML
Conclusion

Introduction

If you've spent even a small amount of time on the Internet, you've probably noticed by now that Extensible Markup Language (XML) is very popular. XML has become the standard language for describing and delivering data on the Web, just as the Hypertext Markup Language (HTML) is the standard language for creating and displaying Web pages. And, just as with many new technologies, there are lots of concepts and buzzwords that can make understanding and putting this exciting new language to practical use difficult, to say the least.

Beginning in Microsoft® Access 2002, it is now easy to import and export XML data as well as transform your XML data to and from other formats. This article provides hints, suggestions, and links to other articles that explain some of the intricacies of XML and, hopefully, take some the mystery out of using XML with Access.

XML Specifics

HTML provides a fixed set of predefined elements (or tags) that tell browsers how to format and display information (or data) on the Web. However, HTML tags do not describe the data itself. For instance, HTML doesn't answer questions such as: does a particular piece of numeric data represent a date, a part of a mathematical equation, a musical score, or a customer's postal code; how do you indicate on an electronic invoice that a phone number is a required field; and what if you wanted to filter, sort, find, or work with the information in other ways? This is where XML can provide a rich way to describe virtually any type of data or document, from a poem to a database. For more information on the basics of XML and how you can define your own tags for describing data, see About XML and Access (Revised).

Unlike HTML, where you have a predefined set of tags and attributes, XML allows you to create your own set of data tags and assign them any names you like — thus the term extensible in the title. However, with this freedom comes risk. For example, how can you distinguish one tag in an XML data document from another? Likewise, how can you insure that the <Number> element you created to designate an element in a mathematical equation isn't confused with the <Number> element created by your coworker to designate the number of widgets ordered? One way of minimizing the problem of conflicting names is through the use of namespaces. Namespaces uniquely qualify element and attribute names so that one application can identify the elements designated exclusively for its use and another application can identify a different set of elements for its use. This means that you can have multiple instances of an element in your XML document, with each element being recognized and associated with a different context.

Another powerful use of XML is its ability to convert or transform data from XML to another format. You may have seen a similar concept used with HTML and Cascading Style Sheets. In the case of XML, the "vehicle" used to define these transformations is an XML-based language called Extensible Stylesheet Language Transformations (XSLT). XSLT is a subset of another XML-based language, the Extensible Stylesheet Language (XSL). XSL is used to define the formatting of XML documents, and XSLT contains templates and commands to select and manipulate the structure of the data. More information about these terms, and examples of using XSLT to transform XML data, can be found in Transform XML files with XSLT.

And of course, there are many more XML articles available.

Access Specifics

In addition to providing a sophisticated way to work with other data, Access 2002 also provides an easy way to work with XML data. You can import XML data into Access from any application that supports the XML standard including text files, spreadsheets, third-party databases, and so on. From Access, you can also export the data, the schema (as an .xsd file), or both, to XML files. For information on the three most common scenarios involving XML in Access (importing XML data into Access, exporting data from Access as XML, and transforming XML data by using an XSLT file once it is exported outside of Access), see Use XML and Access. For the procedures to export data as XML and set advanced XML exporting options in Access 2002, see Export to XML from Access (Revised).

When exporting schema information (information describing the structure of the XML data), Access 2002 also supports a subset of the XML Schema Definition (XSD) language. The primary purpose of XSD is to allow applications to describe XML documents so that other applications that use these documents can be sure that the document conforms to their intended structure. The XSD language, which is supported by the World Wide Web Consortium (W3C), contains dozens of commands to support describing the structure of XML data. However, Access supports only a subset of these XSD commands. For information on which XSD commands that Access 2002 supports, see XML Schema commands supported by Access.

Access 2002 also exports another XML-related file that describes the properties, format, and other characteristics of Access datasheets, forms, or reports. This file, called a ReportML file, when used in conjunction with an XSLT file and XML data, can be used to transform the Access object into other presentation formats, reorder the structure of the data or document, or dynamically sort and filter the data, thus making it easy to use the object in other applications. For more information about ReportML and examples of using it with Access data, see About ReportML in Access 2002.

XML and Data Access Pages

You can also use other objects from an Access database with XML, such as data access pages. For example, in Access 2002, you can include XML data in your data access page in one of three ways. First, you can link the page to an XML data file by taking the page offline in Microsoft Internet Explorer. Second, you can set data access page properties inside of Access to allow the page to bind to an external XML data file. Third, you can set page properties to embed the XML data directly inside of the page. For information on these approaches and typical scenarios for using XML and data access pages, see Include XML in data access pages.

Programmatically Work with XML

You can also work with XML data in Access programmatically by using the ExportXML and ImportXML methods. These methods underwent substantial changes between the time that the Access 2002 Help topics were developed and Access 2002 was completed and shipped. Updated information on these methods can be found in the article Importing from and Exporting to XML.

Conclusion

XML provides an ideal solution for storing and delivering information on the World Wide Web. In this article, you learned about some of the intricacies of XML and ways that you can work with XML data in Access 2002.