Today I noticed XElement.Parse
is not working for a case in my application and throwing an exception. Then turns out an invalid character (in this case &
) was the cause. I had a line as follow in my xml string:
<label content="name1 & name2" startX="9" startY="69" >
I looked around the internet and could not find a good comprehensive solution because people mostly suggest to replace some special characters in the xml text before using XElement.Parse
command.
Since I am not a XML expert and the content of the xml text is totally dynamic, what is the best solution in this case? By the way, I need to have the original text in my XElement object because it's going to be printed as a PDF file.