I have the following XML:
<?xml version='1.0' ?>
<foo>A>B</foo>
and just want to get the node value of start tag as A>B
, if we use getNodeValue it will convert it to A>B which is not needed.
Hence I decided to use the Transformer
Document doc = getParsedDoc(abovexml);
TransformerFactory tranFact = TransformerFactory.newInstance();
Transformer transfor = tranFact.newTransformer();
transfor.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
Source src = new DOMSource(node);
StringWriter buffer = new StringWriter();
Result dest = new StreamResult(buffer);
transfor.transform(src, dest);
String result = buffer.toString();
But this gives the following output as part of result as <foo>A>B</foo>
It will be helpful if somebody could clarify, if there is an approach with which we can get A>B
without doing string manipulation from the above output (<foo>A>B</foo>
)