Inferring Columns

When inferring a schema for a DataSet from an XML document, after ADO.NET has determined which elements to infer as tables it then determines, from the remaining XML elements and attributes, what columns to infer for those tables. Because data type information is only available with an inline schema, the data type of an inferred column is System.String. The following XML structures will result in table columns.

Attributes

As defined in Inferring Tables, an element with attributes will be inferred as a table. The attributes of that element will then be inferred as columns for the table. The ColumnMapping property of the columns will be set to MappingType.Attribute, to ensure that the column names will be written as attributes if the schema is written back to XML. The values of the attributes are stored in a row in the table. For example, consider the following XML:

<DocumentElement>
  <Element1 attr1="value1" attr2="value2"/>
</DocumentElement>

The inference process will produce a table named "Element1" with two columns, "attr1" and "attr2". The ColumnMapping property of both columns will be set to MappingType.Attribute.

DataSet: DocumentElement

Table: Element1

attr1 attr2
value1 value2

Elements without Attributes or Child Elements

If an element has no child elements or attributes, it will be inferred as a column. The ColumnMapping property of the column will be set to MappingType.Element. The text for child elements is stored in a row in the table. For example, consider the following XML:

<DocumentElement>
  <Element1>
    <ChildElement1>Text1</ChildElement1>
    <ChildElement2>Text2</ChildElement2>
  </Element1>
</DocumentElement>

The inference process will produce a table named "Element1" with two columns, "ChildElement1" and "ChildElement2". The ColumnMapping property of both columns will be set to MappingType.Element.

DataSet: DocumentElement

Table: Element1

ChildElement1 ChildElement2
Text1 Text2

See Also

Inferring DataSet Relational Structure from XML | Loading a DataSet from XML | Loading DataSet Schema Information from XML | XML and the DataSet | Creating and Using DataSets