Attribute Centric and Element Centric XML

If you take a look at the XML file generated in Hands-On 29-13 (see Figure 29-23 above), you will notice that below the XML document's root tag there are two child nodes: <s:Schema> and <rs:data>.

The schema node describes the structure of the recordset, while the data node holds the actual data. Inside the <s:Schema id="RowsetSchema"> and </s:Schema> tags, ADO places information about each column: field name, position, data type and length, nullability, and whether the column is writable. Each field is represented by the <s:AttributeType> element. Notice that the value of the name attribute is the field name. The <s:AttributeType> element also has a child element <s:datatype>, which holds information about its data type (integer, number, string, etc.) and the maximum field length.

Below the schema definition, you can find the actual data. The ADO schema represents each record using the <z:row> tag. The fields in a record are expressed as attributes of the <z:row> element. Every XML attribute is assigned a value that is enclosed in a pair of single or double quotation marks; however, if the value of a field in a record is Null, the attribute on the z:row is not created. Notice that each record is written out in the following format:

<z:row ProductID='1' ProductName='Chai' SupplierID='1' CategoryID='1' QuantityPerUnit='10 boxes x 20 bags' UnitPrice='18' UnitsInStock='39' Units0n0rder='0' ReorderLevel='10' Discontinued='False'/>

The code fragment above is attribute-centric XML that Access cannot import. To make the XML file compatible with Access, you should have each record written out as follows:

<Product>

<ProductID>1</ProductID> <ProductName>Chai</ProductName> <SupplierID>1</SupplierID> <CategoryID>1</CategoryID>

<QuantityPerUnit>10 boxes x 20 bags</QuantityPerUnit> <UnitPrice>18</UnitPrice> <UnitsInStock>39</UnitsInStock> <Units0n0rder>0</Units0n0rder> <ReorderLevel>10</ReorderLevel> <Discontinued>False</Discontinued> </Product>

The code fragment above represents element-centric XML. Each record is wrapped in a <Product> tag, and each field is an element under the <Product> tag.

0 0

Post a comment