My XML tags contains ‘ &qout; as part of tag values.
While parsing with following code it changes to ‘ ” & respectively.
I tried apply some logic as to apply changes only to the values present under the tags
for(String tag: tagList) {
NodeList nodeList = doc.getElementsByTagName(tag);
if (nodeList.getLength() >= 1) {
Node node = nodeList.item(0);
if (node.getNodeType() == Node.ELEMENT_NODE) {
Element element = (Element) node;
// Get the text content of the <languages> element
String content = element.getTextContent();
// Replace escape characters within the content
content = content.replace("'", "'");
content = content.replace(""", """);
// Set the modified content back to the <languages> element
element.setTextContent(content);
}
}
}
But still it didn’t work its actually causing further issue.
Transformer transformer = trFactory.newTransformer();
DOMSource source = new DOMSource(doc);
StringWriter writer = new StringWriter();
StreamResult result = new StreamResult(new StringWriter());
transformer.transform(source, result);
the above code converts again to ‘ and ” respectively causing further issues.
Solution on Transformer of Java XML parsing
Swami is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.