Results 1 to 4 of 4

Thread: reading xml from a string

  1. #1

    Thread Starter
    Fanatic Member venerable bede's Avatar
    Join Date
    Sep 2002
    Location
    The mystic land of Geordies
    Posts
    1,018

    reading xml from a string

    I have a string which contains XML and would like to read that xml into a datatable but for the life of me cant figure out how.

    Any Ideas folks ?

    Parksie

  2. #2
    Lively Member mightor's Avatar
    Join Date
    Apr 2007
    Location
    Turn around, I'm right behind you...
    Posts
    99

    Re: reading xml from a string

    I did something similar in my code:
    vb Code:
    1. Dim sr As New System.IO.StringReader(_xmlString)
    2.  
    3. ' The XmlTextReader
    4. Dim xr As New System.Xml.XmlTextReader(sr)
    5.  
    6. ' The XmlDocument
    7. Dim serverStatus As New System.Xml.XmlDocument
    8. serverStatus.Load(xr)
    9.  
    10. Dim serverNodes As System.Xml.XmlNodeList = serverStatus.SelectNodes("rs/r")
    11. Dim currentServer As System.Xml.XmlNode
    12. .
    13. .
    14. .
    Then you can extract the nodes and do with them as you please. Please note that the last couple of lines are very specific to my app.

    Gr,
    Mightor
    Last edited by mightor; May 3rd, 2007 at 07:59 AM. Reason: Hit send too quickly.
    What the world needs is more geniuses with humility, there are so few of us left.
    If my post was accidentally useful, please rate it as such, thanks!
    Mon aéroglisseur est plein des anguilles.

  3. #3

    Thread Starter
    Fanatic Member venerable bede's Avatar
    Join Date
    Sep 2002
    Location
    The mystic land of Geordies
    Posts
    1,018

    Re: reading xml from a string

    I'm a bit lost with that.

    I need to read it into a datatable and the datatable overloads will take the following:

    • string filename
    • System.io.stream stream
    • System.io.textreader reader
    • xmlreader reader

    Parksie

  4. #4
    Lively Member mightor's Avatar
    Join Date
    Apr 2007
    Location
    Turn around, I'm right behind you...
    Posts
    99

    Re: reading xml from a string

    Quote Originally Posted by venerable bede
    I'm a bit lost with that.

    I need to read it into a datatable and the datatable overloads will take the following:

    • string filename
    • System.io.stream stream
    • System.io.textreader reader
    • xmlreader reader
    vb Code:
    1. Dim sr As New System.IO.StringReader(yourxmlstring)
    2. Dim xr As New System.Xml.XmlTextReader(sr)
    3. Dim yourDataTableInstance As New DataTable
    4. yourDataTableInstance.ReadXml(xr)

    That should do the trick. It turns the String into a StringReader and then feeds that to a XmlTextReader which is fed to ReadXml.

    Gr,
    Mightor
    What the world needs is more geniuses with humility, there are so few of us left.
    If my post was accidentally useful, please rate it as such, thanks!
    Mon aéroglisseur est plein des anguilles.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width