0

I have a string that I'm trying to parse to XML like this:

XElement.Parse(XMLdata)

But the problem I'm having is that XMLdata contains this text:

$#x0 resulting in the following exception : '.', hexadecimal value 0x00, is an invalid character. Line 1, position 6554. when trying to parse the string to XML.

Is there a way to remove those characters before calling XElement.Parse(XMLdata)?

Please assist

  • Could you post the XML you are trying to parse? – Alex Filipovici May 27 '13 at 07:14
  • 1
    I found the answer: I replaced the specific text with an empty string before parsing: XElement.Parse(XMLData.Replace("", "")); Solved my problem. Thanks. – user2306342 May 27 '13 at 07:17
  • If it fails, that means the data is not a valid XML file. I highly advise you to ensure that the generated XML (whatever generate its) is a correct XML file. – Steve B May 27 '13 at 07:26

1 Answers1

0

Replace all special characters in your xml content before parse its

"
&
'
<
>
ducmami
  • 215
  • 1
  • 2
  • 1
    This seems to be a poor solution. I believe a solution that ensure the correctness of the XML where it is generated is a far better solution. Better than tweaking strings to force the parser to load the XML – Steve B May 27 '13 at 07:24