| | Product Information Help and How-to Training Templates Support and Feedback Technical Resources Additional Resources | Warning: You are viewing this page with an unsupported Web browser. This Web site works best with Microsoft Internet Explorer 6.0 or later, Firefox 1.5, or Netscape Navigator 8.0 or later. Learn more about supported browsers.
Working with XML data in Access
| Applies to |
Microsoft Office Access 2003 Microsoft Access 2002 |
Extensible Markup Language (XML) is the standard language for describing and delivering data on the Web, just as Hypertext Markup Language (HTML) is the standard language for creating and displaying Web pages. Access provides ways to both import and export XML data as well as transform the data to and from other formats using XML related files.
About XML
Moving information across the Internet and between software applications has always been difficult due to differences in data formats and proprietary structures. HTML, while well suited for providing text and image display information for Web browsers, is limited in its ability to define data and data structures. HTML describes how a Web page should look, whereas XML defines the data and describes how the data should be structured. XML is a data interchange format in that it allows you to exchange data between dissimilar systems or applications. XML separates the data from the presentation so that the same XML data can be presented in multiple ways by using different presentation files.
XML is a standards-based protocol that is governed by the World Wide Web Consortium (W3C). The XML protocol is a set of rules, guidelines, and conventions for designing data formats and structures, in a way that produces files that are easy to generate and easily read by different computers and applications. In addition, XML defined structures are unambiguous; that is, they are self-describing and platform-independent. Like HTML, XML makes use of tags and attributes, but while HTML specifies what each tag and attribute means (and thus how the data between them will look in a browser), XML uses the tags only to delimit pieces of data and leaves the interpretation of the data completely to the application that reads it. Additional information about XML can be found on the MSDN Web site.
About importing XML data
Access provides choices for using data from many external sources and by using XML, it is easier than ever to transform the data from almost any external application. You can use the Import command (point to Get External Data on the File menu) to import XML data files into Access.
What are XML schemas?
With Access 2002 or later, you can export a schema of the Access object, either embedded in the XML data file or as a separate XML Schema Definition (XSD) file. XML schemas are used to describe the structure of data in a common format that customers, other Web browsers, and any number of XML-enabled software programs can recognize. Specifically, schemas define the rules of an XML data document, including element names and data types, which elements can appear in combination, and which attributes are available for each element. Schemas provide a model for an XML data document which defines the arrangement of tags and text within all documents referencing the schema. Access supports the XSD. XSD is a proposed World Wide Web Consortium (W3C) standard designed as a basic infrastructure for describing the type and structure of XML documents.
By using a schema, you can insure that the application receiving an Access-generated XML document understands the data and the defined structure of the document. Other organizations and applications can also provide their schemas to you so that you will know how to structure any data that you provide to them. Access 2002 does not support importing schemas.
Displaying XML data
XML syntax (the tags and their placement in a document) defines and describes the data in an XML document but doesn't indicate how the data should be displayed. In earlier applications and in some current uses, Cascading Style Sheets (CSS) were used to tell browsers how to display the XML data. However, a CSS isn't always a good choice because they are written in a specialized language which means that the developer has to use another language in order to write, modify, or understand the structure of the style sheet. A CSS merely allows you to specify the formatting of each XML element without much control over the output.
On the other hand, an Extensible Stylesheet Language (XSL) style sheet is considerably more flexible than a CSS file. It allows you to precisely select the data that will be displayed, to specify the order or arrangement of the data and to modify or add information. Additionally, it is written in a style similar to an XML document using a combination of XML-like tags and HTML to create a template for a specific style of output. You can export data using a XSL style sheet by choosing the Export Presentation option from the Export XML dialog box. Additional information about XSL style sheets can be found on the MSDN Web site.
About exporting to XML files
Exporting data and database objects to an XML file is a convenient way to move and store your information in a format that can readily be used across the Web. In Access, you can export the data the schema (as an .xsd file), or both, to XML files.
Exporting tables, queries, views, datasheets, forms or reports
You can export a database object as an XML document in several ways:
- You can export just the data from a table, query, datasheet, form, or report into an XML file. This data is saved to a file named <filename>.xml.
- You can export just the schema (data structure) of a table, query, datasheet, form, or report to an XML schema file. An XML schema file is a formal specification of the rules for an XML document, providing a series of element names, as well as which elements are allowed in the document and in what combinations. If you select to save the schema as XSD, the file is saved as <filename>.xsd.
- If selected, you can also can save the structure of a table, query, datasheet, form, or report into a file that describes the presentation and connection information. For forms and reports, this file is saved in an XML-based language called ReportML which provides presentation data as well as a data model for creating a data access page. For tables, queries/views, and datasheets, the presentation file is a spreadsheet-like template. This file is saved as <filename>_report.xml.
- In addition, when you choose to save the data as XML, you can specify that the data be transformed to a custom display format by using an existing .xsl file. If no .xsl file is specified, the data is saved in standard XML format. Note that if no data is selected for export then a presentation format is also unavailable. The file is saved as <filename>_report.xml.
What is ReportML?
ReportML is a "markup language" developed by Microsoft and specific to Access 2002 which can be used to describe Access database objects in XML. The ReportML language is made up of a set of tags that describe a form, report or data access page's properties, events, and attributes. When you export data from Access to an XML file by using the ExportXML method and set the appropriate flag, you can choose to save the structure of a form or report into a ReportML format. The ReportML file created by Access could be used to create a data access page.
Well-formed documents
Any XML document produced by Access is well-formed, which means that it conforms to the basic rules of XML. That is:
| Character |
Entity |
| < |
< |
| & |
& |
| > |
> |
| " |
" |
| ' |
' |
The following is an example of a well-formed XML document:
<?xml version="1.0"?>
<DATAROOT>
<ORDER>
<CUSTOMER>Nancy Davolio</CUSTOMER>
<PRODUCT>
<ITEM>Mom's Boston Crab Meat</ITEM>
<PRICE>$10.00</PRICE>
<QUANTITY>1 Bottle</QUANTITY>
</PRODUCT>
</ORDER>
</DATAROOT>
where: <?xml version="1.0"?> is a declaration that states that this is an XML document and gives the version number. The declaration is optional but is recommended in any XML document. <DATAROOT> is the root element which encompasses the entire document. <CUSTOMER> is a start tag and </CUSTOMER> is an end tag which together describe an element of data in this case, the customer's name.
Notice that each tag set, such as <CUSTOMER></CUSTOMER> , has both start and end tags and is case sensitive, and that the tag sets are properly nested within each other. Also notice the entity ' which will be transformed to an apostrophe (') when the data is imported by the receiving application. The apostrophe has a special purpose in an XML document and can be misinterpreted if used directly in the text. The converted data will be displayed as Mom's Boston Crab Meat.
White space can be used throughout the document to enhance readability.
If a schema is specified while exporting from Access, then the XML documents created are considered to be valid XML document. This means that in addition to being well-formed, the documents conform to a defined schema.
|