XML for DataTable

1

I've been researching how to pass the data contained in an XML to a DataTable and found the following response .

Doubt:

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

    
asked by anonymous 01.03.2017 / 15:14

2 answers

3

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

It would look something like this:

theDataSet.ReadXml(theReader, XmlReadMode.InferSchema);
    
01.03.2017 / 15:27
1

It is possible, yes it all depends on the XML creation, I use an api in the company, and it returns data as follows

<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'DataSet.ReadXml (theReader); ' and the data will already be formatted, it all depends on the preformatting of your XML

    
01.03.2017 / 18:23