尝试使用以下java代码解析其中包含转义字符的XML文件时出错。有没有办法在解析文件时处理它?
private Document parseXmlFile(String fileName) {
Document doc = null;
try {
File fXmlFile = new File(fileName);
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
doc = dBuilder.parse(fXmlFile);
doc.getDocumentElement().normalize();
} catch (ParserConfigurationException | SAXException | IOException ex) {
System.out.println(ex);
}
return doc;
}
示例XML
<ResultDetail>
<ObjectType>APF</ObjectType>
<ObjectName>dlgCreateNewEmployee</ObjectName>
<Header>AccessModifiers Detected</Header>
<Description>&Original source: private</Description>
</ResultDetail>
答案 0 :(得分:0)
<ResultDetail>
<ObjectType>APF</ObjectType>
<ObjectName>dlgCreateNewEmployee</ObjectName>
<Header>AccessModifiers Detected</Header>
<Description>&Original source: private</Description>
或者您也可以使用CDATA