http xml encoding

  • Thread starter Thread starter Mark
  • Start date Start date
M

Mark

I'm sending an xml stream through an http connection to my webserver.
Since some of the xml data will have the same characters as the 'xml
characters'(i.e <,>, etc...), I need the xml to be encoded for the
server. For example, is it a standard practice to encode the >
characer as &gt; in the xml ?

Will this do it ?

Dim oEncoder As New System.Text.ASCIIEncoding
requestData = oEncoder.GetBytes(xmlString)

if this is not the correct way to do it, could someone please show me
the correct way ?

Sorry to add another topic, but also this xml data will contain byte
data from a scanned image in one of the fields, so there is a
possibility it will have chr(0) in the data also. If I need to
prepend data to the xml string (so I need to make a copy of it) can I
just assign it to another string or will it get truncated at the
chr(0) like it would in C.

Thanks,
mark
 
Mark,

See for your first problem this thread where Ger had in my opinion the same
goals as you
http://tinyurl.com/6t4ne

For your second problem you first need to serialize your picture what is not
to difficult, see the sample I once made bellow. (and the deserialize is as
well in it)

\\\Needs a form with a picturebox and 1 button
Private Function SerializeByte(ByVal _
imagestring As Byte()) As String
Dim bf As New Runtime.Serialization.Formatters.Binary.BinaryFormatter
Dim mem As New IO.MemoryStream
bf.Serialize(mem, imagestring)
Return Convert.ToBase64String(mem.ToArray())
End Function
Private Function DeserializeString(ByVal _
imagestring As String) As Byte()
Dim bf As New Runtime.Serialization.Formatters.Binary.BinaryFormatter
Dim mem As New IO.MemoryStream(Convert.FromBase64String(imagestring))
Return DirectCast(bf.Deserialize(mem), Byte())
End Function
'Test program
Private fo As New OpenFileDialog
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
If fo.ShowDialog = DialogResult.OK Then
Dim fs As New IO.FileStream(fo.FileName, _
IO.FileMode.Open)
Dim br As New IO.BinaryReader(fs)
Dim abyt As Byte() = br.ReadBytes(CInt(fs.Length))
br.Close()
Dim myresultstring As String = SerializeByte(abyt)
Dim abyt2 As Byte() = DeserializeString(myresultstring)
Dim ms As New IO.MemoryStream(abyt2)
Me.PictureBox1.Image = Image.FromStream(ms)
End If
End Sub
///

I hope this helps?

Cor
 

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

Similar Threads

change XML encoding 6
Mime encode string 1
Reading XML Encoding errors 12
Can't figure out this XmlTextReader exception. 1
XML Encoding woes... 4
add a node to XMLDocument 1
encoding 1
queuing ideas 6

Back
Top