0

I have two node having same name. i want to modify one particular node value. For example

 <names> 
    <name>one</name> 
    <name>two</name>
    <name>three</name> 
    <name>four</name> 
    <name>five</name> 
    </names>

In the above example i want to change last node value "five" to new value "six". is this possible in DOM..?? i am new to this concept, please guide me. Thanks for valuable replies.

2
  • Use Google to learn about DOM, and then learn how implement DOM parsing in Java. Commented Jun 30, 2011 at 4:44
  • Thank you guys i got answer from google. if anyone having issues like this please refere rgagnon.com/javadetails/java-0625.html this will guide you. Commented Jun 30, 2011 at 6:11

3 Answers 3

1

Here's an example of doing exactly what you describe.

http://www.java2s.com/Code/Java/XML/JavaDOMeditLocateaNodeandChangeItsContent.htm

Sign up to request clarification or add additional context in comments.

Comments

1

The A-Z of DOM using java: http://www.roseindia.net/xml/dom/

Comments

1

Yes. In particular, you can reference collections of child objects of 'names' as a NodeList. see Node.getChildNodes()

Comments

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.