Connecting Tech Pros Worldwide Help | Site Map

XmlTextReader.Read() and ampersand?

Dave
Guest
 
Posts: n/a
#1: Nov 12 '05
XmlTextReader reader = new XmlTextReader
("c:/downloads/somedata.xml");

while (reader.Read())
{
....etc.
}

I've determined that the problem in the source XML is a
node that contains an attribute that doesn't have the
ampersand encoded as "&"

<item security="Common Stock (Class A, B & C)">

How do I manage this because when the Read() method above
reaches this portion of the XML document, I get a parsing
error. How do I encode "&" prior to the Read() somehow?

Dave.


Oleg Tkachenko
Guest
 
Posts: n/a
#2: Nov 12 '05

re: XmlTextReader.Read() and ampersand?


Dave wrote:
[color=blue]
> I've determined that the problem in the source XML is a
> node that contains an attribute that doesn't have the
> ampersand encoded as "&amp;"
>
> <item security="Common Stock (Class A, B & C)">
>
> How do I manage this because when the Read() method above
> reaches this portion of the XML document, I get a parsing
> error. How do I encode "&" prior to the Read() somehow?[/color]

No help from XmlReader. XML documents cannot contain unescaped &, full
stop. So before working with this file as XML first escape all & using
non-XML tools, such as regexp. Or better fix application which produces
such non-wellformed XML.
--
Oleg Tkachenko
XML Insider
http://www.tkachenko.com/blog

Closed Thread