dotnet / dotnet/dotnet-api-docs

Missing information pertaining to using ReadXml(XmlReader)

Open
#967 0 comments 0 reactions 0 assignees View on GitHub
area-System.Data dotnet-api/prod Pri2 untriaged
Dominant language
C#
Stars
949
Forks
1.7k
Avg merge
3d 27m
Merged PRs (30d)
49

Description

This documentation is missing important information about using ReadXml(XmlReader):

1) XML data that does not have schema nodes can be loaded into a table, but you must first explicitly add columns to the DataTable before calling ReadXml() See DataTable.Columns.Add()

2) The name of the table (DataTable.TableName) MUST match the XML element name of the nodes to be read in. For example, if the XML has something like <SomeRecords><row><FirstName>David</FirstName></row></SomeRecords>, in order to load this XML into a DataTable, TableName MUST be set to "row". If the TableName does not match the XML row element, no rows will be imported. (The table name can be changed to any desired name after the call ReadXml() is completed). **This is non-intuitive, and should be documented.

3) If the table has columns for which values are not present in a row that is read from XML, these columns will have a value of {System.DBNull} after the call to ReadXml(), EVEN IF these columns define a default value. To work around this limitation, you can add a column with a default value after the call to ReadXml() is complete. This will assign the default value to the newly-added rows. **This is non-intuitive, and should be documented.

4) DataTable.ReadXml() can be passed a reader that was created with .ReadSubtree() if you want to read only a portion of the XML data into a DataTable.

5) To troubleshoot problems you may encounter while using DataTable.ReadXml(), consider using DataSet.ReadXml() and inspecting the resulting DataSet.Tables[0] This can provide clues (such as how the DataTable should be named).

6) An example of reading a simple XML document into a DataTable using ReadXml(XmlReader) should be provided in the documentation. This is a common scenario, and one for which there is incomplete and erroneous information littered across the internet.

---
#### Document Details

⚠ *Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.*

* ID: 086a15b5-b5fb-06d8-bf6d-9ba7b46a8ea7
* Version Independent ID: cbb2cd3c-f02e-b691-9098-a6080c17bb2d
* Content: [DataTable.ReadXml Method (System.Data)](https://docs.microsoft.com/en-us/dotnet/api/system.data.datatable.readxml?view=netframework-4.7.2)
* Content Source: [xml/System.Data/DataTable.xml](https://github.com/dotnet/dotnet-api-docs/blob/master/xml/System.Data/DataTable.xml)
* Product: **dotnet-api**
* GitHub Login: @douglaslMS
* Microsoft Alias: **douglasl**

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.