Online Book Reader

Home Category

Access Cookbook - Ken Getz [329]

By Root 2027 0
?>

Mini Cooper

S

$20,000

Lexus

LS430

$60,000

There are three parts to the namespace declaration:

xmlns: identifies the dataroot element as containing an XML namespace.

od: identifies the prefix assigned to the namespace.

"urn:schemas-microsoft-com:officedata" is the Uniform Resource Identifier, or URI, which uniquely identifies the namespace. This particular namespace is generated whenever you save Access data in XML format.

In this example, all of the elements in the document are part of one namespace, but multiple namespaces can be used in a single XML document. In that case, the prefix assigned to each namespace is used with the element names to identify which namespace they belong to. This allows differentiation between identically named elements from different namespaces.

When you view an XML file in a browser, you can see the hierarchy of data, as shown in Figure 18-1.

Figure 18-1. Viewing the XML file in a browser window

Clicking the plus sign (+) expands the tree view so that you can view the data in the nested elements.

Attributes


Another option is to represent the data using attributes in addition to elements. Each attribute has a name and a value, as shown in this example where each Car element has a Make, Model, and Price attribute:

You can represent the data as either elements or attributes. However, when you import or export XML data with Access, you have no choice—you must use elements, not attributes, for Access to be able to correctly parse the XML file. One major problem is that if your XML input is not structured using elements, then you may not like the way that Access imports the data. To get around this problem, you need to convert your XML to the element-based format that Access expects. To get around this limitation, you can use an XML technology named Extensible Stylesheet Language Transformations, or XSLT.

Extensible Stylesheet Language Transformations (XSLT)


XSLT is an XML-based language for transforming an XML document into another form. The result can be another XML document or any type of text document. XSLT combines some procedural language features along with rule-based language features. XSLT stylesheets are XML documents that define templates and how to apply them. The templates in XSLT documents contain rules for matching XML elements and attributes in the document that is being transformed and instructions for reformatting those elements and attributes. You will often hear XSLT stylesheets referred to as "XSLT transforms," or simply "transforms." In Access 2003, you can use XSLT for transforming XML both when importing and when exporting data.

XML Schema Definition (XSD)


XSD provides a way of describing the structure of data contained in an XML file, as well as constraints applied to the data, including data types. This is similar to the table definitions and relationships you use to define data structure in Access.

When you export data, you can have Access generate a schema, or XSD, file that describes the data. When importing XML, you can import an XSD file to define the structure and data types of the data being imported. When you import XSD files, Access creates tables based on the definitions in the files.

18.1. Import XML Structured as Elements


Problem


You need to import simple XML data into a new table.

Solution


You can import XML into a new table from the File menu when the Tables category is selected in the Objects pane by following these steps:

Open 18-01.MDB.

Choose File → Get External Data → Import to bring up the Import dialog box.

In the Files of type drop-down list at the bottom of the dialog

Return Main Page Previous Page Next Page

®Online Book Reader