Problems with XmlTextReader

C

CD

Hi,

I am trying to load an XML text file using an
XmlTextReader using a BufferedStream.

I am using the following code:
(assuming m_reader is a valid XmlTextReader)

while (m_reader.Read())
{
if (m_reader.NodeType!=XmlNodeType.Element)
continue;

if (m_reader.LocalName == "ESWBS")
{
while (m_reader.MoveToNextAttribute())
{
// process attributes here
}
}
}

On a document formatted as below...

..
..
..
<ESWBS ID="Something" Notes="" />
<ESWBS ID="Something Else" Notes="" />
..
..
..

I keep the following XmlException during the Read() call:
'<', hexadecimal value 0x3C, is an invalid attribute
character. Line 66, position 18.
at System.Xml.XmlScanner.ScanLiteral()
at System.Xml.XmlTextReader.SetLiteralValues
(XmlAttributeTokenInfo fld)
at System.Xml.XmlTextReader.SetAttributeValues()
at System.Xml.XmlTextReader.ParseElement()
at System.Xml.XmlTextReader.Read()
at MPAS.AdvIO.MPASTextReader.Read(NodeGraph graph) in
c:\projects\mpas\mpas.advio\mpastextreader.cs:line 91
at MPAS.NET.Doc.ReadMPASTextDocument(String filename)
in C:\Projects\MPAS\MPAS.NET\Doc.cs:line 398

The XML document was generated by another class in the
application which uses an XmlTextWriter for producing the
document. The document is also well-formed (at least
according to Internet Explorer).

Just to be sure that there weren't any '<' tags inside
quotes, I did a regex search using ".*\<.*" and found
nothing.

Whenever I test the code on different documents generated
by this application, I get the same XmlException (or a
similar one, complaining that '<' can't be part of an
attribute name or element name) in different parts of the
document. The same error will always happen consistently
in the same part of the same document however, but
different parts of different documents.

Any ideas? Please post response here.

Thanks,
CD
 
O

Oleg Tkachenko [MVP]

CD said:
if (m_reader.LocalName == "ESWBS")
{
while (m_reader.MoveToNextAttribute())
{
// process attributes here


Your code looks ok. Most likely the problem is in the code part you
didn't show. How do you process attributes? Looks like you are moving
reader somehow screwing up the reading.
 

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