XMLTextReader - Issue with sepcial characters &,<,>

  • Thread starter Thread starter RJN
  • Start date Start date
R

RJN

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>
<EmployeeStrength>> 1000</EmployeeStrength>

When I do a Xmltextreader.read() and then check the contents of the xml
node by XmltextReader.ReadString(), I get an exception when I have
special characters. How do I handle this?

Thanks

rjn
 
RJN,
XMLTextReader only reads "well formed" XML!

| <CompanyName>Johnson & Jhonson</CompanyName>
Is not "well formed" XML...

Change the above to:
<CompanyName>Johnson &amp; Jhonson</CompanyName>

Remember in XML that '&' is "&amp;" while '<' is "&lt;" and '>' is "&gt;".
See "2.4 Character Data and Markup" at
http://www.w3.org/TR/2004/REC-xml-20040204/

Hope this helps
Jay


| 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>
| <EmployeeStrength>> 1000</EmployeeStrength>
|
| When I do a Xmltextreader.read() and then check the contents of the xml
| node by XmltextReader.ReadString(), I get an exception when I have
| special characters. How do I handle this?
|
| Thanks
|
| rjn
|
|
|
|
|
 

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

Back
Top