Can't figure out this XmlTextReader exception.

T

Terry Olsen

I use the following code to create an XML string:

Private Function CreatePacket(ByVal pt As PacketType) As String
Dim xmlDoc As TextWriter = New StringWriter
Dim xmlWriter As New XmlTextWriter(xmlDoc)
With xmlWriter
..IndentChar = " "
..Indentation = 4
..Formatting = Formatting.Indented
..WriteStartDocument()
..WriteStartElement("BoycoTChatPacket")
..WriteStartElement(pt.ToString)
..WriteAttributeString("UID", "BoycoTChatServer")
..WriteAttributeString("IP", "192.168.0.3")
..WriteAttributeString("Port", "9999")
..WriteAttributeString("Nick", "BoycoTChatServer")
..WriteEndElement() 'pt.ToString
..WriteEndElement() 'BoycoTChatPacket
..WriteEndDocument()
..Flush()
..Close()
End With
xmlDoc.Close()
Return xmlDoc.ToString
End Function

It creates this XML string:

<?xml version="1.0" encoding="utf-16"?>
<BoycoTChatPacket>
<Pong UID="BoycoTChatServer" IP="192.168.0.3" Port="9999"
Nick="BoycoTChatServer" />
</BoycoTChatPacket>

I use the following code to read the XML:

'xmlString contains the XML shown above
Dim xmlReader As New XmlTextReader(xmlString)

And it throws an exception..."Invalid characters in path"

Can anyone see what's wrong here? I'm stumped.

Thanks.
 
T

Terry Olsen

Nevermind, I found my mistake. The correct code to read the xmlString is
thus:

Dim sr As New StringReader(rcvd)
Dim xmlReader As New XmlTextReader(sr)
 

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