The character encoding of an XML file should be validated to ensure that the text within the XML file can be correctly displayed or read by systems without any "broken character" problems. The ideal method for validating the character encoding of an XML file is a 2 step process.
- First, the XML file can be checked to ensure that it contains only byte sequences that are valid Unicode. This is fairly straightforward and there are libraries available to check Unicode encoding of any text file, which can be applied to XML file because XML is essentially text.
- Second, after the XML file has been parsed check that the text nodes and attribute values contain only valid Unicode characters. This can be done using using regular expressions in XPath, Schematron, XQuery, Java, etc.
The XML Recommendation specifies that XML should be encoded using Unicode character set. Some XML parsers might reject an XML file that contains byte sequences that are not valid Unicode, however tho