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. XML / XSL
  4. Converting XML-string into Dataset

Converting XML-string into Dataset

Scheduled Pinned Locked Moved XML / XSL
sysadminxmlhelptutorialquestion
5 Posts 3 Posters 6 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.
  • P Offline
    P Offline
    Preben Rasmussen
    wrote on last edited by
    #1

    I am having a hard time converting a string representation of a xml-document into a dataset. The case is: 1. I send a request to a server which answers with a xml-document in the form of a string. 2. Next I want to convert this string into a System.Data.DataSet and display it in a datagrid or some other. It is giving me a really hard time figuring out how to do this. I have tríed the following: { System.Xml.XmlDataDocument xmlDD = new System.Xml.XmlDataDocument(); System.Data.DataSet dsXML = new System.Data.DataSet(); xmlDD.LoadXml(strXml); dsXml = xmlDD.DataSet; } This will generate following error "The IListSource does not contain any data sources." I have tried the following, it works, but is a VERY bad idea for a webpage: { xmlDD.LoadXml(strXml); xmlDD.Save(Server.MapPath("log") + "\\out.xml"); dsXml.ReadXml("\\out.xml"); } Why can't I go directly from a string through a xmldocument to a dataset? Any comments appreciated. Preben Rasmussen IT-consultant

    Richard DeemingR M 2 Replies Last reply
    0
    • P Preben Rasmussen

      I am having a hard time converting a string representation of a xml-document into a dataset. The case is: 1. I send a request to a server which answers with a xml-document in the form of a string. 2. Next I want to convert this string into a System.Data.DataSet and display it in a datagrid or some other. It is giving me a really hard time figuring out how to do this. I have tríed the following: { System.Xml.XmlDataDocument xmlDD = new System.Xml.XmlDataDocument(); System.Data.DataSet dsXML = new System.Data.DataSet(); xmlDD.LoadXml(strXml); dsXml = xmlDD.DataSet; } This will generate following error "The IListSource does not contain any data sources." I have tried the following, it works, but is a VERY bad idea for a webpage: { xmlDD.LoadXml(strXml); xmlDD.Save(Server.MapPath("log") + "\\out.xml"); dsXml.ReadXml("\\out.xml"); } Why can't I go directly from a string through a xmldocument to a dataset? Any comments appreciated. Preben Rasmussen IT-consultant

      Richard DeemingR Offline
      Richard DeemingR Offline
      Richard Deeming
      wrote on last edited by
      #2

      One of the overloads of the ReadXml method accepts a TextReader object. The StringReader class is derived from TextReader, so you can just do:

      System.IO.StringReader sr = new System.IO.StringReader(strXml);
      System.Data.DataSet dsXML = new System.Data.DataSet();
      dsXML.ReadXml(sr);


      "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

      "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

      P 1 Reply Last reply
      0
      • P Preben Rasmussen

        I am having a hard time converting a string representation of a xml-document into a dataset. The case is: 1. I send a request to a server which answers with a xml-document in the form of a string. 2. Next I want to convert this string into a System.Data.DataSet and display it in a datagrid or some other. It is giving me a really hard time figuring out how to do this. I have tríed the following: { System.Xml.XmlDataDocument xmlDD = new System.Xml.XmlDataDocument(); System.Data.DataSet dsXML = new System.Data.DataSet(); xmlDD.LoadXml(strXml); dsXml = xmlDD.DataSet; } This will generate following error "The IListSource does not contain any data sources." I have tried the following, it works, but is a VERY bad idea for a webpage: { xmlDD.LoadXml(strXml); xmlDD.Save(Server.MapPath("log") + "\\out.xml"); dsXml.ReadXml("\\out.xml"); } Why can't I go directly from a string through a xmldocument to a dataset? Any comments appreciated. Preben Rasmussen IT-consultant

        M Offline
        M Offline
        MS le Roux
        wrote on last edited by
        #3

        I also find it annoying that there isn't a simple way of loading a dataset from a string. Here's one way that's a bit of a rigmarole but it does the job: Dim srForData As System.IO.StringReader = New System.IO.StringReader(StringToLoadFrom) Dim rdrForData As System.Xml.XmlReader = New System.Xml.XmlTextReader(srForData) DataSetToLoad = New DataSet() DataSetToLoad.ReadXml(rdrForData)

        P 1 Reply Last reply
        0
        • Richard DeemingR Richard Deeming

          One of the overloads of the ReadXml method accepts a TextReader object. The StringReader class is derived from TextReader, so you can just do:

          System.IO.StringReader sr = new System.IO.StringReader(strXml);
          System.Data.DataSet dsXML = new System.Data.DataSet();
          dsXML.ReadXml(sr);


          "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

          P Offline
          P Offline
          Preben Rasmussen
          wrote on last edited by
          #4

          Thanks a lot - it works great. Just what I wanted. Preben Rasmussen

          1 Reply Last reply
          0
          • M MS le Roux

            I also find it annoying that there isn't a simple way of loading a dataset from a string. Here's one way that's a bit of a rigmarole but it does the job: Dim srForData As System.IO.StringReader = New System.IO.StringReader(StringToLoadFrom) Dim rdrForData As System.Xml.XmlReader = New System.Xml.XmlTextReader(srForData) DataSetToLoad = New DataSet() DataSetToLoad.ReadXml(rdrForData)

            P Offline
            P Offline
            Preben Rasmussen
            wrote on last edited by
            #5

            This one also works fine - thanks. Preben Rasmusen

            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