Results 1 to 4 of 4

Thread: Read an XML String into a Dataset

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Dec 2002
    Posts
    196

    Read an XML String into a Dataset

    I receive an xml file as a string, across a socket, and I want to import that string into a dataset.

    Here's my code so far but it doesn't work.

    VB Code:
    1. Dim ms As New System.IO.MemoryStream
    2. Dim sw As New System.IO.StreamWriter(ms)
    3.  
    4. sw.Write(xmlFileString)
    5. ms.Position = 0
    6.  
    7. Dim ds As New DataSet
    8. ds.ReadXml(ms)
    9. ms.Close()

    Here's my xml string

    <?xml version="1.0" encoding="iso-8859-1" ?>
    <banlist>
    <ban>
    <datetime>Wed Mar 08 21:21:38 2006</datetime>
    <nick>ParaDiddle[BF2CC]</nick>
    <method>Key</method>
    <period>Perm</period>
    <address>127.0.0.1</address>
    <cdkeyhash>b5b1074e479b8bd89df9cae38fa2c1f6</cdkeyhash>
    <profileid>44681561</profileid>
    <by>admin</by>
    <reason>BANNING!!! ParaDiddle[BF2CC] for Team Killing!</reason>
    </ban>
    <ban>
    <datetime>Thu Mar 09 07:13:49 2006</datetime>
    <nick>=[BFT]=Sr7</nick>
    <method>Key</method>
    <period>Perm</period>
    <address>24.5.22.132</address>
    <cdkeyhash>2edb0a0062a7ec9c7407edaafd3ec315</cdkeyhash>
    <profileid>45281450</profileid>
    <by>admin</by>
    <reason>BANNING!!! =[BFT]=Sr7 for Team Killing!</reason>
    </ban>
    </banlist>
    Brandon S Davids

  2. #2
    Member hardyvoje's Avatar
    Join Date
    Feb 2006
    Location
    Serbia
    Posts
    38

    Re: Read an XML String into a Dataset

    I think that you should load string into XmlDocument object like:
    VB Code:
    1. dim XmlDoc as new Xmldocument
    2. XmlDoc.InnerXml = XmlString

    XmlString is XML in string that you get as input.

    After first part of code you will have proper XML document that you need to assign to dataset. I don't know exactly how but that shouldn't be a problem.

    Look at Dataset namespace if there is something with XML, or try to set your XmlDoc as Dataset's datasource....

    something like:
    dim DatasetObj as Dataset
    DatasetObj.Datasource = XmlDoc
    Free tutorials, web templates, images, 3D models and other design&developing resources at: http://www.omnetwork.net | Open Source Gaming Portal: www.osgamer.org

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Dec 2002
    Posts
    196

    Re: Read an XML String into a Dataset

    I cant find a way to go from xmldoc to dataset if I use that method.

    I'm pretty sure I need to be using streams here.
    Brandon S Davids

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Dec 2002
    Posts
    196

    Re: Read an XML String into a Dataset

    OK, I can do this if I save the xml to a file first using the following code but shoudln't I be able to do this with a memorystream so that I don't have to save the file?

    VB Code:
    1. Dim s As String = Comm.Player.GetBanHistory(Comm.Token)
    2.  
    3.                 SaveTextToFile(s, Application.StartupPath & "\banlist.xml")
    4.  
    5.                 Dim fsReadXml As New System.IO.FileStream(Application.StartupPath & "\banlist.xml", IO.FileMode.Open)
    6.                 Dim myXmlReader As New System.Xml.XmlTextReader(fsReadXml)
    7.                 Dim ds As New DataSet
    8.  
    9.                 ds.ReadXml(myXmlReader)
    10.                 grdBanlist.DataSource = ds
    Brandon S Davids

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