A problem with DataSet while reading XML

Hi

I have a question. It is regarding reading an XML file. I tried asking it in the XML section but somehow they weren't able to help me out and suggested that anybody in the Data section might be helpful for me. Hence I'm asking the question out here.

I have a XML file - some of the content I'm pasting here for your reference....

<fareDetails><segmentRef><segmentRef>1</segmentRef></segmentRef><productInformation><avlProductDetails><rbd>Q</rbd><avlStatus>9</avlStatus><cabin>M</cabin></avlProductDetails><fareProductDetail><fareBasis>QLNNGB1CH</fareBasis><passengerType>CNN</passengerType><fareType>RP</fareType></fareProductDetail></productInformation></fareDetails><fareDetails><segmentRef><segmentRef>2</segmentRef></segmentRef><productInformation><avlProductDetails><rbd>Q</rbd><avlStatus>9</avlStatus><cabin>M</cabin></avlProductDetails><fareProductDetail><fareBasis>QLNNGB1CH</fareBasis><passengerType>CNN</passengerType><fareType>RP</fareType></fareProductDetail></productInformation></fareDetails></paxFareProduct><paxFareProduct><paxFareDetail><paxFareNum>3</paxFareNum><totalFareAmount>111.00</totalFareAmount><totalTaxAmount>65.00</totalTaxAmount></paxFareDetail><paxReference><ptc>INF</ptc><traveller><ref>1</ref><infantIndicator>1</infantIndicator></traveller></paxReference><fare><pricingMessage><freeTextQualification><messageQualifier>PEN</messageQualifier><messageCode>70</messageCode></freeTextQualification><description>TICKETS ARE NON-REFUNDABLE</description></pricingMessage></fare>

I want to read this XML file and show the values in the Data Grid. I'm using this piece of code :-

Dim myDataSet As New DataSet()
myDataSet.ReadXml(Server.MapPath("pfarea.xml"))
DataGrid1.DataSource = myDataSet
DataGrid1.DataBind()

The project works fine for any other xml file but not the one I want to read and part of which is mentioned above. The error I'm getting is :-

"The same table (segmentRef) cannot be the child table in two nested relations."

In the XML section Sergey suggested that this luimitation is imposed by DataSet and the exception is thrown by the System.Data.dll

Please suggest me how can I solve this issue.

Best Regards.

Genie

PS: The thread in XML section for reference:- http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=466024&SiteID=1&mode=1




Answer this question

A problem with DataSet while reading XML

  • VivSB

    DataSet only guaranteed to load XML which represents serialized DataSet and was created with DataSet.WriteXml(). DataSet also has a process called inference (this name by itself should suggest to stay away from it) in which it would try to “guess” schema from XML, but it’s not guaranteed.

    This XML you're trying to load does not represent dataset and inferred schema is not valid for DataSet, so it fails. There's no way to fix that without changing XML.



  • ChoKamir

    Assuming you are using ADO.NET v2.0, I think you may be hitting into a bug/unsupported XML.

    In the attached XML <segmentRef> is both a 1)nested table inside of <fareDetails> and 2) a SimpleContent column of <segmentRef> table.

    If possible try using XSLT or similar mechanisms to either:

    1) change the name of <segmentRef> - the column of <segmentRef> the table or

    2) change <segmentRef> column element to be attribute centric like <segmentRef segmentRef="10' />.

    Hope it helps.

    Kawarjit Bedi

    kbedi@microsoft.com



  • A problem with DataSet while reading XML