0

I am facing a problem while parsing the XML file. Actually one of element tag in the XML file contains a special character which is &

<organization>AT&T</organization>

and for parsing this xml file i am using-

 XDocument xmlDoc = XDocument.Parse(xml);

and when my xml file goes for parsing i am getting following exception- ' ' is an unexpected token. The expected token is ';'. Line 43, position 15.

How to handle it so that i could have my original data i.e AT&T and also i bypass this exception. Any link or help would be highly appropriated.

svick
  • 236,525
  • 50
  • 385
  • 514
Sunil Singh
  • 255
  • 1
  • 5
  • 8
  • Then you have invalid XML files. Step 1 is to insist that whatever generates those files gets fixed to avoid spreading the sickness. As a workaround, try the links above and look for a preprocessing solution. – Oskar Berggren Feb 12 '13 at 11:55
  • I fixed it by replacing all the invalid special chars in the text file and then create the valid xml file. Is it good idea or there is any best idea? – Sunil Singh Feb 12 '13 at 12:20
  • @SunilSingh: XML parsers expect a valid XML file, if you don't have a valid XML file, then you need to do preprocessing to get a valid file first. So yes, that is probably the best solution. – Guvante Feb 12 '13 at 15:34

0 Answers0