Home > Articles > Web Services > XML

  • Print
  • + Share This
Like this article? We recommend

Like this article? We recommend

Importing XML Information into an Access Database

After customers have placed orders for crafts on a web site, we can upload the order information to the Crafty database via an XML document returned from the site. This strategy enables the crafter to maintain centralized records locally.

Suppose the order entry web site outputs the following XML file (called order.xml), complete with the included order data:

 <?xml version="1.0" encoding="UTF-8" ?>
- <dataroot xmlns:od="urn:schemas-microsoft-com:officedata"
- <order>
 <ShipName>John Jones</ShipName>
 <ShipAddress>1234 any street</ShipAddress>
 <ShipCity>your city</ShipCity>
 <Product_x0020_Name>seaside cottage</Product_x0020_Name>
- <order>
 <ShipName>Jackie Jones</ShipName>
 <ShipAddress>345 Blue Road</ShipAddress>
 <Product_x0020_Name>flower pot candle 3"</Product_x0020_Name>
- <order>
 <ShipName>Tom Jones</ShipName>
 <ShipAddress>134 main</ShipAddress>
 <Product_x0020_Name>flower pot candle 1</Product_x0020_Name>

We can simply import this data into an existing Access database, uploading into an existing table, a new table, or even a new database.

To import the data, choose File, Get External Data, Import (see Figure 11). Select XML in the Files of Type list.

Figure 11Figure 11 Importing an XML file.

Access infers the target table name from the following line in the file we're importing (see Figure 12):


Figure 12Figure 12 Specifying the target table.

You can import all of the information from the XML file, or select which inferred columns are imported into the database (see Figure 13).

Figure 13Figure 13 Selecting the columns to import.

If you import the data without specifying any options, the data will be loaded into a new table in the database (see Figure 14). This technique allows you to examine the information to determine its legitimacy, accuracy, and ability to fit in with the other data in the table. For example, you may prefer state abbreviations, shipping addresses, and names to have appropriate capitalization; if so, you could opt to import the data into a new table and make your own transformations on the data to keep your base tables clean.

Figure 14Figure 14 The new table resulting from a basic import operation.

Figure 15 shows the result you get if you opt to simply append the data to an existing table; information in a field is imported into the corresponding columns.

Figure xxxFigure 15 Appended data.

  • + Share This
  • 🔖 Save To Your Account