DataSet.Readxml() missing column for repeating nodes

Last post 11-07-2009 12:35 PM by vishwaraj1. 8 replies.

Sort Posts:

  • DataSet.Readxml() missing column for repeating nodes

    11-05-2009, 1:59 PM
    • Member
      25 point Member
    • sawhneyg
    • Member since 07-17-2006, 2:45 PM
    • Posts 8

    Hi,

    I am trying to create the datset from the following xmlstring. The only unique thing    about the xml is it has two similar child node version with different values for the parent  node object. when i look at the column returned from the dataset, it doesnot contain the column for the repeating nodes. version 

    any suggestion is appreciated.

    string xml = "<?xml version=\"1.0\"?>\n<root>\n

    <object >\n

    <version>1.0</version>\n

    <version>CURRENT<version>\n

    <object_id>123</object_id>\n

    <object_name>Documnet</object_name>\n

    </object>\n</root>\n";

    StringReader xmlSR = new StringReader(xml);

    DataSet dsInbox = new DataSet();

    dsInbox.ReadXml(xmlSR, XmlReadMode.Auto); return dsInbox;

     Thanks

     Gaurav

     

     

     

     

  • Re: DataSet.Readxml() missing column for repeating nodes

    11-05-2009, 6:42 PM
    • Member
      220 point Member
    • Ryan_A
    • Member since 10-28-2009, 12:06 AM
    • Rochester, NY
    • Posts 45

    If it is an option I would redesign your XML schema and name the 2nd Version node something else.  It doesn't really make any sense to have two sibling nodes with the same name and different datatypes.  You would never design a database table that way, why do it with an XML file?


    Ryan Andreotta, MCPD
    http://www.rackwire.com
    Shared hosting from $4.99/month
    VPS from $22.00/month
  • Re: DataSet.Readxml() missing column for repeating nodes

    11-05-2009, 8:39 PM
    • Member
      25 point Member
    • sawhneyg
    • Member since 07-17-2006, 2:45 PM
    • Posts 8

    hi Ryan,

    Thanks for the reply,I would agree that you should not design in such a way.but i am getting this from the object model exposed by the one of the products that my client is using and i have no control over the database. i can only interact with the database using exposed object model, which gives me the xml in the above format.

    Thanks

    Gaurav

  • Re: DataSet.Readxml() missing column for repeating nodes

    11-05-2009, 8:48 PM
    • Member
      220 point Member
    • Ryan_A
    • Member since 10-28-2009, 12:06 AM
    • Rochester, NY
    • Posts 45

    Ok, when I ran this the first problem I ran into was that your 2nd version node is missing the closing /

    You have <version>CURRENT<version>


    Instead of <version>CURRENT</version>


    After correcting that The datatable that is returned has the column in it.  Specifically my DataTable contained the columns:

    version
    version_Text


    Ryan Andreotta, MCPD
    http://www.rackwire.com
    Shared hosting from $4.99/month
    VPS from $22.00/month
  • Re: DataSet.Readxml() missing column for repeating nodes

    11-05-2009, 8:57 PM
    • Member
      220 point Member
    • Ryan_A
    • Member since 10-28-2009, 12:06 AM
    • Rochester, NY
    • Posts 45

    Sorry, that does not fix the problem, you actually get two DataTables back, and one is just named version.

    I would suggest a couple possible solutions that aren't ideal but should work.

    1.  Use a regular expression to change the name of the 2nd node in the xml string, so you can read it using InferSchema and everything should come out OK.

    2.  Create your DataTable by hand, use an XmlDocument object, traverse the document manually and populate the DataTable.



    Ryan Andreotta, MCPD
    http://www.rackwire.com
    Shared hosting from $4.99/month
    VPS from $22.00/month
  • Re: DataSet.Readxml() missing column for repeating nodes

    11-05-2009, 11:30 PM

    sawhneyg:

     am getting this from the object model exposed by the one of the products that my client is using and i have no control over the database. i can only interact with the database using exposed object model, which gives me the xml in the above format.



    After you receive this XML you can write XSLT over it and transofm the xml the way you want.


    Please mark this post as Answer if it is of help to you!

    " Every wall is a door..! "
  • Re: DataSet.Readxml() missing column for repeating nodes

    11-06-2009, 10:41 AM
    • Member
      25 point Member
    • sawhneyg
    • Member since 07-17-2006, 2:45 PM
    • Posts 8

    there could be a possibility where any number of repeating nodes can appear, is there a generic way to handle when there are repeating nodes, convert them into a single node with values separated by comma.  

  • Re: DataSet.Readxml() missing column for repeating nodes

    11-07-2009, 12:16 PM
    Answer

    yahh you could wrtite xslt which would do the same thing for u.... 

    Please mark this post as Answer if it is of help to you!

    " Every wall is a door..! "
  • Re: DataSet.Readxml() missing column for repeating nodes

    11-07-2009, 12:35 PM
    • Participant
      1,641 point Participant
    • vishwaraj1
    • Member since 11-07-2008, 2:44 PM
    • India
    • Posts 424

    try this to get the data in dataset
    
    DataSet authorsDataSet;
            string filePath = Server.MapPath("grid.xml");
            authorsDataSet = new DataSet();
            //Read the contents of the XML file into the DataSet
            authorsDataSet.ReadXml(filePath);
    



    Regards:

    Vishwaraj Malik

    VB to C# Converter


    Please: Don't forget to click "Mark as Answer" on the post that helped you. That way future readers will know which post solved your issue.
Page 1 of 1 (9 items)