XML Files


XML stands for eXtensible Markup Language. You have likely heard the XML buzzword, but you may not know what XML files really are. XML is a syntax that enables systems to create simple text documents with various tags that identify how the text should be interpreted. At the end of this section, you will create an XML document from a table so that you can see what one looks like.

The idea behind XML is to give various types of operating systems on different platforms a meaningful way of communicating with one another. As the use of XML has grown in popularity, the need to write Access applications that can import and export to XML text files has increased. Recent versions of Microsoft products incorporate extended XML functionality, including the ImportXML and ExportXML methods that Access provides to enable users to import from and export to XML databases. You will now look at each of these in turn.

The syntax for the ImportXML method is:

  Application.ImportXML DataSource, ImportOptions 

The DataSource is the name and path of the XML file to import. The ImportOptions parameter can be acStructureAndData (default), acAppendData, or acStructureOnly. Thus, to import an XML document into a table in your Access database, you might use the following code:

  Application.ImportXML "employees.xml", acStructureAndData 

The ExportXML method allows you to export data in your Access database to XML files to exchange data with other applications. Here is the syntax:

  Application.ExportXML ObjectType, DataSource, DataTarget, SchemaTarget, PresentationTarget, ImageTarget, Encoding, OtherFlags, WhereCondition, AdditionalData 

The following table explains what the various parameters of the ExportXML object are used for.

Open table as spreadsheet

Parameter

Description

ObjectType

The type of Access object to export

DataSource

The name of the Access object to export

DataTarget

The file name and path for the exported data

SchemaTarget

The file name and path for the exported schema

PresentationTarget

The file name and path for the exported target information

ImageTarget

The path for exported images

Encoding

The text encoding to use

OtherFlags

Additional flags that can be used

WhereCondition

Subset of records to be exported

AdditionalData

Additional tables to export

I said earlier that I would provide a sample XML file so that you could see what it looks like. Well, it’s now time to use the ExportXML method to export one of your tables to XML so that you can see how it works.

Suppose that you have the following procedure:

  Sub TestExportXML() Application.ExportXML acExportTable, "tblEmployees", _     "c:\Temp\Employees.xml", _     "c:\Temp\EmployeesSchema.xml" End Sub 

The procedure uses the ExportXML method to export the Employees table in your database to an XML file called Employees.xml. After you run the preceding procedure, you create the XML file that looks similar to the one shown in Figure 7-6.

image from book
Figure 7-6

Notice in Figure 7-6 how the tags describe the data in detailed ways. This is a more detailed and structured way of organizing and describing data than HTML, which is just designed for displaying data.

That’s all it takes to export data from your Access application to another system. You’re now ready to learn how to send an e-mail from VBA code.




Beginning Access 2007 VBA
Beginning Access 2007 VBA
ISBN: 0470046848
EAN: 2147483647
Year: 2004
Pages: 143

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