1

I face problem while reading the following value from xml file using C#

xml data contains <Address>ASST. manager, MAINTANANCE & dept  </Address>
Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
  • 1
    Hello. Please proved some sample code, examples of what you have tries and any exceptions or logs generated. Cheers. – Nico Nov 12 '13 at 07:48
  • 2
    @Nico, something tells me that the problem is not within the code, but between the specs. He receives an error because the parser encountered a special character. The `&` should be replaced with `&`. – Andrei V Nov 12 '13 at 07:49
  • I receive error: " '.', hexadecimal value 0x00, is an invalid character. Line 13636, position 34. " I understand that the problem is reading the '&' But i need to read it, how? – Mizanur Rahman Milon Nov 12 '13 at 07:54
  • If you have access to the generation of the XML, save all the elements inside a `CDATA`: `
    <![CDATA[ASST. manager, MAINTANANCE & dept]]>
    `. You will not be able to use the `&` as plain text otherwise.
    – Andrei V Nov 12 '13 at 07:57
  • I have no permission in generation of the XML, I want to read only- AndreiV – Mizanur Rahman Milon Nov 12 '13 at 08:01
  • 4
    Well, that's not a valid XML. The only way I can think of for reading it is to implement your own XML parser. I don't think you want that... If you know the supplier of the XML, ask them to use `CDATA` inside all elements. If not, try to open the file as a text file and either replace special characters or add `CDATA` elements yourself. – Andrei V Nov 12 '13 at 08:09
  • Instead of wrapping the text in `CDATA` you could replace the `&` with `&`. As it is it's invalid XML. – Hans Kesting Nov 12 '13 at 08:14
  • @HansKesting, that's actually what I would do. It the most simple solution. I suggested `CDATA` as there might be other special characters as well. – Andrei V Nov 12 '13 at 08:17
  • http://stackoverflow.com/questions/1091945/where-can-i-get-a-list-of-the-xml-document-escape-characters – adt Nov 12 '13 at 08:20
  • Another problem: My data is as Designation="OFFICER GRADE G - II", but when xml is generated the xml file contains some illegal character and looks like OFFICER GRADE b II This xml create a problem in the time of reading the xml file by C# – Mizanur Rahman Milon Nov 13 '13 at 09:13

0 Answers0