473,386 Members | 1,720 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Can't figure out this XmlTextReader exception.

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.
Apr 9 '06 #1
1 1317
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)

"Terry Olsen" <to******@hotmail.com> wrote in message
news:e8****************@TK2MSFTNGP02.phx.gbl...
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.

Apr 9 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Qin Zhou | last post by:
This is possible memory leak can be reproduced by the following code. I am hoping someone can help me out with simple solutions! Thanks in advanced! using System; using System.IO; using...
2
by: Ed Bacon | last post by:
I am a bit puzzled about the differences between XmlTextReader and XmlValidatingReader. I have been able to successfully load a DataSet object from and XML file via the text reader. However,...
4
by: Cheryl Gilbert | last post by:
I'm sending xml to a web service by building a string dynamically. When my web service tries to validate the xml with a schema, I'm getting the error "the root element is missing". If I use an xml...
1
by: RJN | last post by:
Hi I'm using XMLTextReader to parse the contents of XML. I have issues when the xml content itself has some special characters like & ,> etc. <CompanyName>Johnson & Jhonson</CompanyName>...
3
by: Willi | last post by:
Hallo, i have to validate many XML's Documents with a XSD. Some XML's throw a Validationerror like "The 'type' attribute has an invalid value according to its data type". To produce automatically...
1
by: Jordan | last post by:
I have a unicode XML file that I am trying to read using the .NET XmlTextReader in C#. How do I read the unicode file? If I try to using the XmlTextReader.Read() method, it throws an exception. ...
2
by: Michael | last post by:
Hi All, I have something going wrong with the XmlTextReader. I have a function that reads the following XML example. For some reason the code is only getting two of the 3 Values elements. Here is...
5
by: =?Utf-8?B?TWlrZQ==?= | last post by:
Hi! I have an application that retrieves its settings from an Apache server XML file. The application bombs at this line for one user only: m_XMLReader = new XmlTextReader(configFileURL); ...
0
by: =?Utf-8?B?Slc=?= | last post by:
I read some advice given to someone here to use RegEx to get around invalid XML characters. Goran Djuranovic asked the question in 1-21-2007. The advice was given by Keith Patrick and Goran...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.