wood burning stoves 2.0*
The moose likes XML and Related Technologies and the fly likes adding and removing elements from DOM in java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "adding and removing elements from DOM in java" Watch "adding and removing elements from DOM in java" New topic
Author

adding and removing elements from DOM in java

Brandon Broschinsky
Ranch Hand

Joined: Aug 21, 2004
Posts: 41
i have written a program that store address book information in a XML file. I can read the data into a dom tree and navigate up and down the tree when a user presses a button to display the next entry. I want to be able to add and delete elements. I am having trouble getting this. the structure of my XML is as follows:

<?xml version="1.0" encoding="iso-8859-1"?>
<Address_Book>
<entry>
<fName>first name</fName>
<lName>last name</lName>
<address1>first part</address1>
<address2>first part</address2>
<city>city</city>
<state>state</state>
<zip>zip</zip>
<phone>phone</phone>
<cell>cellphone</cell>
<email>email address</email>
<notes>this is important</notes>
</entry>
</Address_Book>

Only I have multiple entry elements with listed children. I would like to be ableo to remove an entry section with all children and add one as well with the children. Any help is appreciated.
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
Have you seen JavaAlmanac.com?


Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12806
    
    5
Unless I totally misunderstand your problem, all the methods you want are in org.w3c.org.Node Interface.
Bill
Brandon Broschinsky
Ranch Hand

Joined: Aug 21, 2004
Posts: 41
Thanks to all the replies I got it figured out. I was running into issues about where to add the new nodes.

Thanks
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: adding and removing elements from DOM in java