How to work with XML files in memory?

UncleRonin

Well-known member
Joined
Feb 28, 2006
Messages
230
Location
South Africa
Programming Experience
5-10
I always work with XML if I have to work with configs and the like. Now, I want to generate an XML file and send it across the netowrk to some recipient. I send it across the network line by line because its easiest and it is reassembled on the other side into a file.

At the moment I read an XML file from a drive somewhere and the write it node by node across the network. At the other side this file is reconstructed node by node and written to a file on a drive.

How can I create an XML kinda object with the full information and then send it through the network?

At the very least how do I create an XML object in memory and use it in memory? I know about a bunch of different classes but I have no idea how to use them in memory, I'm only familiar with working with drives and streams.
 
Did I miss something, or did Neal suggest you could use DataSet for Remoting or serialization? :)

By what means do you send the information through the network? Remoting is a topic, but regular Tcp socket communication is just sending bytes. System.Text.Encoding provides methods to convert String<->Bytes. The XmlDocument.OuterXml is the complete string that you can convert to bytes and send. XmlDocument.LoadXml can read the Xml string when you have received the bytes and converted back to string.

Example that shows the conversion back and forth:
VB.NET:
Sub xmlbytes()
  Dim xdoc As New Xml.XmlDocument
  xdoc.Load("testxml.xml")
  Dim enc As System.Text.Encoding = System.Text.Encoding.Default
  Dim bytes() As Byte = enc.GetBytes(xdoc.OuterXml)
  xdoc.LoadXml(enc.GetString(bytes))
  xdoc.Save("testout.xml")
End Sub
I have also some replies related to this and serialization here: http://www.vbdotnetforums.com/showthread.php?t=11783
 
Back
Top