Hi,
I'm using the jaxp1.0.1 and it only has a getElementsByTagName() which returns a nodelist!
This is what I've been trying and I get the following exception
java.lang.ClassCastException: org.apache.xerces.dom.DeepNodeListImpl
Element e=(Element)doc.getElementsByTagName("bm");
Node parent = (Node)e.getParentNode();
String aa=e.getNodeName();
System.out.println("Node selected"+aa);
if(e.getAttribute("id").equals(id1))
{
while(parent.hasChildNodes())
parent.removeChild(parent.getFirstChild());
}
Also I checked out the XML4J parser and even there you get a node list and not a single element
Thanks
Priya
------------- Original Message --------------
"Joe Sabu" <Joe.Sabu@dothill.com> wrote:
To:<general@xml.apache.org>
From:"Joe Sabu" <Joe.Sabu@dothill.com>
Date:Wed, 20 Sep 2000 09:58:31 -0400
Subject: Re: XML- deleting xml tags using DOM
You could, using DOM, traverse right upto the parent of the Node you want to
delete, and call removeChild(node_to_be_removed)
Gor e.g., if you want to remove the bookmark b1,
Elem e = doc.getElementbyId("b1");
Node parent = (Node)e.getParentNode();
parent.removeChild(e);
Hope it helps. BTW, this is the way it is in XML4J, I think it's the same in
Xerces too.
Joe Sabu
----- Original Message -----
From: "Priya Pinto" <itfresher@rediffmail.com>
To: <general@xml.apache.org>
Sent: Wednesday, September 20, 2000 8:22 AM
Subject: XML- deleting xml tags using DOM
Hi,
Could some one help me! I'm working on using an XML file as database and
have been successful in creating a file and also in recalling the file and
adding new records.
The next stage is to be able to delete a particular record and am currently
stuck with this!
If possible could u send me an example?
Here's my xml file:
<?xml version="1.0" ?><?xml:stylesheet type="text/xsl"
href="http://evereadi:8080/bookmark/xsl/Add.xsl"?>
<bookmarks Autonumber="2">
<bm id="b1">
<title>Yahoo</title>
<description>A search engine</description>
<urls>http://www.yahoo.com</urls>
<category>General</category>
</bm>
<bm id="b2">
<title>Ebay</title>
<description>Auction site</description>
<urls>http://www.ebay.com</urls>
<category>Auction</category>
</bm>
</bookmarks>
I could also post the code I've been working with if required.
Thanks
Priya
_________________________________________________
Get Your Free Email At, http://www.rediffmail.com
For fabulous shopping deals visit:
http://www.rediff.co.in/shopping/index.html
---------------------------------------------------------------------
In case of troubles, e-mail: webmaster@xml.apache.org
To unsubscribe, e-mail: general-unsubscribe@xml.apache.org
For additional commands, e-mail: general-help@xml.apache.org
---------------------------------------------------------------------
In case of troubles, e-mail: webmaster@xml.apache.org
To unsubscribe, e-mail: general-unsubscribe@xml.apache.org
For additional commands, e-mail: general-help@xml.apache.org
_________________________________________________
Get Your Free Email At, http://www.rediffmail.com
For fabulous shopping deals visit: http://www.rediff.co.in/shopping/index.html
|