Copy contents of XMLDocument to byte array

J

jcvoon

Hi:

I use the following code to copy the contents of the XMLDocument to
byte array

Dim xmlDoc as New XMLDocument
Dim stream As New MemoryStream
Dim buffers() As Byte

xmlDoc.Load("Sample.xml")
xmlDoc.Save(stream)
buffers = New Byte(CInt(stream.Length + 24)) {}
' First 25 Byte is reserve for special purposes
stream.ToArray.CopyTo(buffers, 25)


I want to optimise the code to avoid to use the MemoryStream

Dim xmlDoc as New XMLDocument
Dim buffers() As Byte

xmlDoc.Load("Sample.xml")
buffers = New Byte(CInt(xmlDoc.outerXML + 24)) {}
' First 25 Byte is reserve for special purposes
ASCIIEncoding.ASCII.GetBytes(xmlDoc.outerXML).CopyTo(buffers, 25)


But the result is not same, when i save the buffer contents to file,
the 1st method is same as the input xml file (Sample.xml), but the 2nd
method will result in xml with smaller file size, all white space has
been removed.

Any idea ?

JCVoon
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top