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:
Dim ms As New System.IO.MemoryStream
Dim sw As New System.IO.StreamWriter(ms)
sw.Write(xmlFileString)
ms.Position = 0
Dim ds As New DataSet
ds.ReadXml(ms)
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>
Re: Read an XML String into a Dataset
I think that you should load string into XmlDocument object like:
VB Code:
dim XmlDoc as new Xmldocument
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
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.
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:
Dim s As String = Comm.Player.GetBanHistory(Comm.Token)
SaveTextToFile(s, Application.StartupPath & "\banlist.xml")
Dim fsReadXml As New System.IO.FileStream(Application.StartupPath & "\banlist.xml", IO.FileMode.Open)
Dim myXmlReader As New System.Xml.XmlTextReader(fsReadXml)
Dim ds As New DataSet
ds.ReadXml(myXmlReader)
grdBanlist.DataSource = ds