Java-处理文本中小于/大于符号的XML
我试图解析文本中带有“小于”和“大于”符号的XML文件 下面是一个示例XML文件:Java-处理文本中小于/大于符号的XML,java,xml,xpath,Java,Xml,Xpath,我试图解析文本中带有“小于”和“大于”符号的XML文件 下面是一个示例XML文件: <document> <summary> The equation for t is: 567<T<600. </summary> </document> 及 但我只想转义文本中的字符 目前,我正在尝试使用DocumentBuilder,但它出错了 DocumentBuilderFactory domFactor
<document>
<summary>
The equation for t is: 567<T<600.
</summary>
</document>
及
但我只想转义文本中的字符
目前,我正在尝试使用DocumentBuilder,但它出错了
DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance();
domFactory.setNamespaceAware(true);
domFactory.setExpandEntityReferences(false);
try {
DocumentBuilder builder = domFactory.newDocumentBuilder();
Document document = builder.parse(new InputSource(new StringReader(sectionXML.toString())));
} catch (ParserConfigurationException e) {
e.printStackTrace();
}
我得到的错误是:
[Fatal Error] :1:70: Element type "T" must be followed by either attribute specifications, ">" or "/>".
org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 70; Element type "T" must be followed by either attribute specifications, ">" or "/>".
有什么想法吗?提前感谢您的帮助。尝试将此类文本放入CDATA节中。我考虑过这一点,但如何解析它以仅将文本包装到CDATA节中?请参见:啊,这似乎是在解析CDATA节的XML,而我的数据中目前不存在该节。因此,您想解析无效的XML吗?
DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance();
domFactory.setNamespaceAware(true);
domFactory.setExpandEntityReferences(false);
try {
DocumentBuilder builder = domFactory.newDocumentBuilder();
Document document = builder.parse(new InputSource(new StringReader(sectionXML.toString())));
} catch (ParserConfigurationException e) {
e.printStackTrace();
}
[Fatal Error] :1:70: Element type "T" must be followed by either attribute specifications, ">" or "/>".
org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 70; Element type "T" must be followed by either attribute specifications, ">" or "/>".