XML for Datatable

Asked

Viewed 113 times

2

I’ve been searching on how to pass the data contained in an XML to a DataTable and found the following reply.

Doubt:

By doing so, the method theDataSet.ReadXml(theReader); is able to identify data types in XML? Or it will create all columns of the DataTableas string?

2 answers

3


You can, at least in certain situations. If you have schema may be better. There is an overload of the method theDataSet.ReadXml() which allows this using enumeration XmlReadMode. You should choose the one that best suits you. Be careful not to rely too much on the inference, test too all situations.

Would something like this:

theDataSet.ReadXml(theReader, XmlReadMode.InferSchema);

I put in the Github for future reference.

2

it is possible yes, everything depends on the creation of XML, I use an api in the company who and returns data in the following way

<xs:element name="LedgerID" type="xs:int" minOccurs="0" />
<xs:element name="sUnit" type="xs:string" minOccurs="0" />
<xs:element name="sSize" type="xs:string" minOccurs="0" />
<xs:element name="Area" type="xs:decimal" minOccurs="0" />

With this data just use the theDataSet.ReadXml(theReader); and the data will already come formatted, everything depends on the pre-formatting of your XML

Browser other questions tagged

You are not signed in. Login or sign up in order to post.