Share via


Inferring Tables

When inferring a schema for a DataSet from an XML document, ADO.NET first determines which XML elements represent tables. The following XML structures will result in a table for the DataSet schema.

Elements with Attributes

Elements that have attributes specified in them will result in inferred tables. For example, consider the following XML:

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

The inference process will produce a table named "Element1".

DataSet: DocumentElement

Table: Element1

attr1 Element1_Text
value1    
value2 Text1

Elements with Child Elements

Elements that have child elements will result in inferred tables. For example, consider the following XML:

<DocumentElement>
  <Element1>
    <ChildElement1>Text1</ChildElement1>
  </Element1>
</DocumentElement>

The inference process will produce a table named "Element1".

DataSet: DocumentElement

Table: Element1

ChildElement1
Text1

The document, or root, element will result in an inferred table if it has attributes or child elements that will be inferred as columns. If the document element has no attributes and no child elements that would be inferred as columns, the element will be inferred as a DataSet. For example, consider the following XML:

<DocumentElement>
  <Element1>Text1</Element1>
  <Element2>Text2</Element2>
</DocumentElement>

The inference process will produce a table named "DocumentElement".

DataSet: NewDataSet

Table: DocumentElement

Element1 Element2
Text1 Text2

Alternatively, consider the following XML:

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

The inference process will produce a DataSet named "DocumentElement" that contains a table named "Element1".

DataSet: DocumentElement

Table: Element1

attr1 attr2
value1 value2

Repeating Elements

Elements that repeat will result in a single inferred table. For example, consider the following XML:

<DocumentElement>
  <Element1>Text1</Element1>
  <Element1>Text2</Element1>
</DocumentElement>

The inference process will produce a table named "Element1".

DataSet: DocumentElement

Table: Element1

Element1_Text
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