msphelix 0 Posted August 16, 2012 Report Share Posted August 16, 2012 Hi, I am displaying Nodes from the following XML file in a Java GUI.<?xml version="1.0" encoding="ISO-8859-1"?><bookstore> <book category="cooking"> <title>Everyday Italian</title> <author>Giada De Laurentiis</author> </book><!-- more book elements --></bookstore>I haveElement documentElement = xmlDocument.getDocumentElement();andNodeList bookNodes = documentElement.getElementsByTagName("book");I want to allow the user to remove all <book> elements while not destroying xmlDocument - I want the user to be able to add <book> elements to the same Document even after removing all of the existing elements.I can do this by running bookNodes from tail to head, getting each element, and calling documentElement.removeChild(thisElement).ButIs there a way to do this in one call?documentElement.removeAll();Thanks. Quote Link to post Share on other sites
boen_robot 107 Posted August 16, 2012 Report Share Posted August 16, 2012 When you want to keep some stuff... no. If you want to completely clean the bookstore element, you could just use replaceChild over the element itself, i.e. xmlDocument.replaceChild(documentElement.cloneNode(false), documentElement); Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.