0

I am trying to get the XML value of a node.

To get the Nodelist i am doing this

NodeList list =  (NodeList) doc.getElementsByTagName("response")

To get particular Node I am doing:

list.item(index);

From the node i can get the text content of the node but I don't know how to get the XML String value of a node.

For example:

<add job="351">
<test>
<tag>foobar</tag>
<tag>foobar2</tag>
</test>
</add>

I can pick the node with tag "test". Now from the Node i want output like this:

<test>
<tag>foobar</tag>
<tag>foobar2</tag>
</test>

Any help is appreciated.

Awadesh
  • 3,530
  • 2
  • 20
  • 32
  • Possible duplicate of [Getting XML Node text value with Java DOM](https://stackoverflow.com/questions/773012/getting-xml-node-text-value-with-java-dom) – sarkasronie Mar 28 '18 at 08:06
  • Its not duplicate, actually i want XML String value of a node. – Awadesh Mar 28 '18 at 08:10
  • Then clarify your question. "XML value of a node" and "text content of a node" are same. Do you need the name of the XML attribute? Then write it, please. – sarkasronie Mar 28 '18 at 08:12
  • 1
    I think you can find your answer here: [Java How to extract a complete XML block](https://stackoverflow.com/a/8980018/5538979) – hadi.mansouri Mar 28 '18 at 08:15
  • @hadi.mansouri Yes it worked thank you :) – Awadesh Mar 28 '18 at 09:18

0 Answers0