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.

5
  • Possible duplicate of Getting XML Node text value with Java DOM Commented Mar 28, 2018 at 8:06
  • Its not duplicate, actually i want XML String value of a node. Commented Mar 28, 2018 at 8: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. Commented Mar 28, 2018 at 8:12
  • 1
    I think you can find your answer here: Java How to extract a complete XML block Commented Mar 28, 2018 at 8:15
  • @hadi.mansouri Yes it worked thank you :) Commented Mar 28, 2018 at 9:18

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.