如何用Java编写Unicode字符0x{2}?
我尝试使用"\u0002",但似乎无法正常工作。
我需要找到该字符的原因是,在能够解析它之前,需要将其替换为XML文件。
我在解析时遇到的错误提到:An invalid XML character (Unicode: 0x{2}) was found in the value of attribute "{1}" and element is "4".和替换\u0002不能解决该错误。
这就是我解析的方式:
try {
// Fixing any invalid characters in the XML file
fixXMLFile(xmlFile);
// Get a factory
SAXParserFactory spf = SAXParserFactory.newInstance();
// Get a new instance of parser
SAXParser sp = spf.newSAXParser();
// Parse the file and also register this class for call backs
sp.parse(xmlFile, this);
} catch(Exception e) {
System.out.println(e.getLocalizedMessage());
}
和修复方法:
private void fixXMLFile(File xmlFile) throws IOException {
File tempFile =