I am trying to parse an XML file with the "less than" and "greater than" symbols in the text.
Here is a sample XML file:
<document>
<summary>
The equation for t is: 567<T<600.
</summary>
</document>
Is there any way to handle this in a Java XML parser? I know about escaping and changing to
<
and
>
but I only want to escape the characters in the text.
Currently, I am trying to use the DocumentBuilder, but it is erroring out.
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();
}
The error I am getting is:
[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 "/>".
Any thoughts? Thanks in advance for any help.