Joe Lau

Hi there,

I tried to read an XML file by using Dataset.ReadXML() method. However, i cannot read some of the "Id" attribute for some elements. But when i checked the XML file, there are values inside.

Anyone can be advised on this

Thanks,

JL



Re: XML and the .NET Framework XML "Id" attribute

Derek Smyth

Hi mate,

You have to specify the ColumnMapping for the column that uses attributes.

When you read XML into a DataSet object that doesn't have any tables (and columns) defined then it expects all data to be stored in elements. If you have data as attributes then you need to create tables (and columns) and for the columns you need to specify how the column maps to the XML. The DataColumn.ColumnMapping property does this. It has a enumeration value of Hidden, Element, Attribute and maybe a few more. You need to build your dataset, maybe not all of it but at least you need to add the tables and the columns which get it's data from attributes.






Re: XML and the .NET Framework XML "Id" attribute

Joe Lau

hi derek,

I have already defined that field in my schema. The most interesting part is that some element can get the value, but one or two cannot.

For example, the "header" element, in the XML file showing as below:-

<HEADER Id="72" Seq="12">

Then in the dataset schema, i defined the column "HEADER_Id". However, after the dataset.readXML() completed. The "Header_Id" has no contents insides.

However, within the same XML file, the "carton" element, it shows:-

+ <CARTON Seq="14" Id="281">

And when i view the "CARTON_Id" column of the dataset, it has '0' inside.

It is very rare. Have any idea why.

Thanks,

JL





Re: XML and the .NET Framework XML "Id" attribute

Derek Smyth

Hi again,

Do me a favor and post an example of your XML data and I'll see if I can replicate the error.