Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. XmlDataSource vs DataSource

XmlDataSource vs DataSource

Scheduled Pinned Locked Moved C#
cssvisual-studiowpfwcfxml
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Malcolm Smart
    wrote on last edited by
    #1

    I have unmanged DLL (legacy - can't touch it!) which returns an XML string. I want to bind this string to a datagrid....easy...or it should be. But I can't. I've isolated the problem below. To get the xml string into a dataset, I use a StringReader and use ReadXml. But when binding to Datagrid, it only shows the root node if I haven't pre bound the columns, or if I have, it complains the field isn't there (as it only exists in teh child nodes). I have saved the output from the Unmanaged DLL to an XML file which can be parsed, so the format is correct. To test, I use two methods of populating the grid. The first one works fine, loading the XML file into an XMLDataSource. The second one doesn't - loading the XML file into a DataSource, via ReadXML. It is this second optoin I need to work, or some method of doing this where i can pass an XML string in. works a treat, but I can't use as I have to receive from a string, not a file

        XmlDataSource xds = new XmlDataSource();
        xds.DataFile = ("d:/test.xml");
    
        GridView1.DataSource = xds;
        GridView1.DataBind();
    

    doesn't work as it only seems to look at root node.

        DataSet ds = new DataSet();
    
        System.IO.StreamReader  str = new StreamReader("d:/test.xml") ;
        StringReader rdr = new StringReader(str.ReadToEnd());
        
        ds.ReadXml(rdr);//**<-- this is the KEY bit as I need to load from a string**
        GridView1.DataSource = ds;
        GridView1.DataBind();
    

    Any ideas?

    Regards Malc *********************************************

    H M 2 Replies Last reply
    0
    • M Malcolm Smart

      I have unmanged DLL (legacy - can't touch it!) which returns an XML string. I want to bind this string to a datagrid....easy...or it should be. But I can't. I've isolated the problem below. To get the xml string into a dataset, I use a StringReader and use ReadXml. But when binding to Datagrid, it only shows the root node if I haven't pre bound the columns, or if I have, it complains the field isn't there (as it only exists in teh child nodes). I have saved the output from the Unmanaged DLL to an XML file which can be parsed, so the format is correct. To test, I use two methods of populating the grid. The first one works fine, loading the XML file into an XMLDataSource. The second one doesn't - loading the XML file into a DataSource, via ReadXML. It is this second optoin I need to work, or some method of doing this where i can pass an XML string in. works a treat, but I can't use as I have to receive from a string, not a file

          XmlDataSource xds = new XmlDataSource();
          xds.DataFile = ("d:/test.xml");
      
          GridView1.DataSource = xds;
          GridView1.DataBind();
      

      doesn't work as it only seems to look at root node.

          DataSet ds = new DataSet();
      
          System.IO.StreamReader  str = new StreamReader("d:/test.xml") ;
          StringReader rdr = new StringReader(str.ReadToEnd());
          
          ds.ReadXml(rdr);//**<-- this is the KEY bit as I need to load from a string**
          GridView1.DataSource = ds;
          GridView1.DataBind();
      

      Any ideas?

      Regards Malc *********************************************

      H Offline
      H Offline
      hamidreza_buddy
      wrote on last edited by
      #2

      err maybe you should use ReadXmlSchema().

      1 Reply Last reply
      0
      • M Malcolm Smart

        I have unmanged DLL (legacy - can't touch it!) which returns an XML string. I want to bind this string to a datagrid....easy...or it should be. But I can't. I've isolated the problem below. To get the xml string into a dataset, I use a StringReader and use ReadXml. But when binding to Datagrid, it only shows the root node if I haven't pre bound the columns, or if I have, it complains the field isn't there (as it only exists in teh child nodes). I have saved the output from the Unmanaged DLL to an XML file which can be parsed, so the format is correct. To test, I use two methods of populating the grid. The first one works fine, loading the XML file into an XMLDataSource. The second one doesn't - loading the XML file into a DataSource, via ReadXML. It is this second optoin I need to work, or some method of doing this where i can pass an XML string in. works a treat, but I can't use as I have to receive from a string, not a file

            XmlDataSource xds = new XmlDataSource();
            xds.DataFile = ("d:/test.xml");
        
            GridView1.DataSource = xds;
            GridView1.DataBind();
        

        doesn't work as it only seems to look at root node.

            DataSet ds = new DataSet();
        
            System.IO.StreamReader  str = new StreamReader("d:/test.xml") ;
            StringReader rdr = new StringReader(str.ReadToEnd());
            
            ds.ReadXml(rdr);//**<-- this is the KEY bit as I need to load from a string**
            GridView1.DataSource = ds;
            GridView1.DataBind();
        

        Any ideas?

        Regards Malc *********************************************

        M Offline
        M Offline
        Malcolm Smart
        wrote on last edited by
        #3

        The Dataset, read from an XML string contains multiple tables. The first table (the default) is the root node, the second table, contains the child nodes...so...changing the following line works a treat..

        //GridView1.DataSource = ds; //defaults to Tables[0] which root node
        GridView1.DataSource = ds.Tables[1];//child nodes - marvellous.

        Regards Malc *********************************************

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups