I am trying to parse xml files. But there is an issue with < .
My XML file example:
<title>
<subtitle> The conclusion is p < 0.1 </subtitle>
</title>
My code is:
XMLInputFactory factory = XMLInputFactory.newFactory();
XMLStreamReader reader = factory.createXMLStreamReader(StringSource);
while (reader.hasNext()) {
switch (reader.next()) {
case XMLStreamReader.START_ELEMENT: {
String tagName = reader.getLocalName();
String path = parent.getPath() + "/" + tagName;
parent.addChild(child);
}
case XMLStreamReader.CHARACTERS: {
String text = reader.getText();
After parsing it, the text I got is: "0.1".
The output I expected is "The conclusion is p < 0.1"
I think the problem is at getText(), how can I fix that?
If you think the problem is getText(), Then rewrite as reader.toString() instead of getText();
Here you can see a parse code.
}