XML parsing often fails because the file contains special characters. There are two reasons: first, the content contains an XML predefined entity, and second, the content contains low-level non-printable characters.
1. the content contains the objects pre-defined in XML, such as "<" and "&", which are forbidden for XML. For such characters, the solution is to use the CDATA component to "<! The [CDATA ["Mark starts with"]> "Mark ends. The internal content of CDATA is ignored by the parser. For more information, see what is xml cdata?
2. If the content contains low-level non-printable characters, an error will be reported during parsing.: "" (Hexadecimal value 0x1d) is an invalid character. exception thrown when loading or saving XML. system. argumentexception: "" (hexadecimal value 0x1d) is invalid character.
The error occurs because the content contains low-level non-printable characters. The processing method is to filter the low-level non-printable characters. The filtering method is as follows:
ReturnSystem. Text. regularexpressions. RegEx. Replace (STR ,@"[\ X00-\ x08] | [\ x0b-\ x0c] | [\ x0e-\ x1f]";
For more information, see XML file error solution! (Transfer).
The first case is more common, and the second case is less common. In the face of some user input data, XML can be generated to filter the content of XML nodes, to ensure that users of XML files can parse XML documents correctly.