1

I'm creating an application that reads Xml from an RSS feed. The problem is that sometimes, some of the data contains special characters such as '&' . For instance:

<row id="AOVP">
<column id="code">AOVP</column>
<column id="sname">AF & OVR 6% PART PRF</column>
<column id="time">18:30:45</column>
<column id="trade">14498</column>
<column id="points">62</column>
<column id="perc">0.43</column>
</row>

I have to reformat this xml so that it looks like this:

<Share>
    <Code>AOVP</Code>
    <ShortName>AF & OVR 6% PART PRF</ShortName>
    <Time>18:30:45</Time>
    <Trade>14498</Trade>
    <Points>62</Points>
    <Perc>0.43</Perc>
</Share>

I have no control over the data I receive, so I can't "clean it". And these special characters make my application crash when I try to reformat the xml for my own purposes. How can I read these values without encountering an XmlException?

PS: I've gone through numerous answers on StackOverflow and other forums, and nothings seems to work.

  • 1
    Please read [MCVE]. You'll need to provide the code you're using to read the XML file which is throwing the XmlException – Mick Jun 30 '20 at 01:03
  • What error is causing the application to crash? – Greg Sansom Jun 30 '20 at 01:15
  • I should also comment that the XML you've supplied is not valid.... AF & OVR 6% PART PRF should be AF & OVR 6% PART PRF – Mick Jun 30 '20 at 01:48
  • And correspondingly your output would need to be AF & OVR 6% PART PRF – Mick Jun 30 '20 at 01:50
  • http://xml.silmaril.ie/specials.html – Mick Jun 30 '20 at 01:51
  • This could be useful too ... https://stackoverflow.com/questions/5700618/xdocument-is-it-possible-to-force-the-load-of-a-malformed-xml-file – Mick Jun 30 '20 at 02:39
  • What URL are you using? Most Feeds are not wrong and produce the correct results. So it may not be the URL and may be something you are doing wrong. When you are failing did you save the URL data to a file and testing from a file? I've seen a lot of cases if you read directly from the URL code works and when you download data to a file and read from a file you get errors like what you are seeing. – jdweng Jun 30 '20 at 07:08

0 Answers0