问题
VB / C# im attempting to parse the XML file which contains the special character,
replace & with &
' with &apos
< with <
> with >
the string replace did not as it replaces the special character '<' , '>' in the the tags. i tried with catch XML exceptions that didn't work when there are multiple special characters in same line, it works if only one special character in a line. the MS builtin method SecurityElement.Escape didn't work, this has to be done before the XML tags are attached.
im using this file to load a SQL table.
Any other solution to handle the XML multiple special characters?
回答1:
use System.Security.SecurityElement.Escape eg : string XmlFriendly = System.Security.SecurityElement.Escape("the bad ' string");
回答2:
Why don't you use XmlTextReader? It should handle all that escaping.
回答3:
If I understand the question correctly, you are not trying to process an XML file, you are trying to process a non-XML file which would be an XML file if the special characters were correctly escaped.
So the question is, where does this non-XML file come from? Because the best way to fix it is to fix the process that created it. Creating bad XML and then repairing it is much more difficult than creating good XML in the first place.
来源:https://stackoverflow.com/questions/11229524/xml-special-character-handling