My xml look like this:
<item> <content><p>hello</p></content> </item>
I want to get the full content from content tag through java. but the function available is getTextContent(). which is returning only hello. How can i get hello with tags
<p>hello</p>
using Java code as below:
File fXmlFile = new File("./Index.xml");
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
Document doc = dBuilder.parse(fXmlFile);
doc.getDocumentElement().normalize();
NodeList nList = doc.getElementsByTagName("item");
for (int temp = 0; temp < nList.getLength(); temp++) {
Node nNode = nList.item(temp);
if (nNode.getNodeType() == Node.ELEMENT_NODE) {
Element eElement = (Element) nNode;
System.out.println(eElement.getElementsByTagName("content").item(0).getTextContent());
}
}