XML (Extended Markup Language)


As a beginner, you will probably not be designing XML documents, but if you use Data Access Pages, you may come across XML. It is one of the major topics in web design. For that reason we are going to take a brief look at the technology.

When you work with HTML, you work with a limited number of available tags (<head>, < body>, < h1>, etc.). These tags describe the structure of the document. You can also design Cascading Stylesheets (CSS) to format these tags. But is the structure of the document that simple?

If you want to connect a database to the web page, as you will probably be doing often with Access, you may need to use tags that reflect the structure of your database. For instance, within the body, you may need tags to reflect the last name, first name, address, and so on. Each one of these tags may need its own formatting rules.

XML permits you to design your own tags to reflect the structure of the database. Once the tags are defined, you can use them as you would any other HTML tag. This adds greatly to the ability to control the design and look of your web page.

Just as an example, here is an XML programming structure, with data from two records:

<?xml version="1.0" encoding="UTF-8"?> <dataroot xmlns:od="urn:schemas-microsoft-com:officedata"  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="tblCustomer.xsd" generated="2003-12-14T15:17:12">   <tblCustomer>   <txtCustNumber>101</txtCustNumber>   <txtCustFirstName>John</txtCustFirstName>   <txtCustLastName>Jones</txtCustLastName>   <txtAddress>123 Main Street</txtAddress>   <txtCity>Hackensack</txtCity>   <txtState>NJ</txtState>   <txtZipCode>07642</txtZipCode>   </tblCustomer>   <tblCustomer>   <txtCustNumber>102</txtCustNumber>   <txtCustFirstName>Jane</txtCustFirstName>   <txtCustLastName>Smith</txtCustLastName>   <txtAddress>1519 Morris Avenue</txtAddress>   <txtCity>Bronx</txtCity>   <txtState>NY</txtState>   <txtZipCode>10469</txtZipCode>   </tblCustomer> </dataroot> 

Notice that there is a hierarchy of structure, with <dataroot> being the highest level, <tblCustomer> being the next, and finally, the fields being the lowest. Also, for every opening tag, there is a corresponding closing tag. What is not obvious is that all tags are case sensitive.

You can have Access set up XML pages for you by first clicking on the table you want to set them up for, and then using File | Export. Once you are in the Export dialog box, select XML as the file type. Once you decide where the file needs to be saved (depending on the directory structure of the web server), you click on Export. You will see the dialog box shown here:

You have a choice of three types of exports. The Data option creates a file with an .xml file extension and exports the structure and data. The code you just looked at is an example of that type of structure.

A Schema creates a file with an .xsd file extension. This will set up the structure without the data.

Finally, Presentation works like a Cascading Style Sheet and uses the file extension .xsl. It formats how the data will look on the web page. The following code excerpt reflects a typical XSL structure:

<?xml version="1.0" ?> - <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"  xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:fx="#fx-functions" exclude- result-prefixes="msxsl fx">   <xsl:output method="html" version="4.0" indent="yes"  xmlns:xsl="http://www.w3.org/1999/XSL/Transform" /> - <xsl:template match="//dataroot"  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> - <html> - <head>   <META HTTP-EQUIV="Content-Type" CONTENT="text/html;charset=UTF-8" />   <title>tblCustomer</title>  <style type="text/css" />   </head>   <body link="#0000ff" vlink="#800080">   <table border="1" bgcolor="#ffffff" cellspacing="0" cellpadding="0" bold">CTRL1">   <colgroup>   <col style="WIDTH: 1.2187in" />   <col style="WIDTH: 0.9375in" />   <col style="WIDTH: 0.9375in" /   <col style="WIDTH: 1.4062in" />   <col style="WIDTH: 0.9375in" />   <col style="WIDTH: 0.9375in" />   <col style="WIDTH: 0.9375in" />   </colgroup>   <tr>   <td>   <div align="center">   <strong>Customer Number</strong>   </div>   </td>   <td>   <div align="center">   <strong>First Name</strong>   </div>  </td>   <td>   <div align="center">   <strong>Last Name</strong>   </div>   </td>

You can also create VBA code in ADO 2.7, which will export XML (although, once again, it is rarely done):

Sub exportXML()   Application.exportXML acExportTable, _   "tblCustomer", _   "c:\accessvba\Customer.xml", _   "CustomerSchema.xml" End Sub 

As I said at the outset, entire books are devoted to the topic of XML. This section serves as a brief introduction.




Access VBA Programming
Microsoft Access VBA Programming for the Absolute Beginner
ISBN: 1598633937
EAN: 2147483647
Year: 2006
Pages: 214
Authors: Michael Vine

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net