RAAAAM
RAAAAM

Reputation: 3380

How to Modify XML using java

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.

Upvotes: 0

Views: 1700

Answers (3)

redbmk
redbmk

Reputation: 4796

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

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

Upvotes: 1

Chris Nava
Chris Nava

Reputation: 6802

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

Upvotes: 1

Anand
Anand

Reputation: 12152

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

Upvotes: 1

Related Questions