Removing ParentNode in a xml document

Hi All,

I have a XML document as below :

<First>

<Second>

<Third>

<Third_x>Some text</Third_x>

<Third_y>Some text</Third_y>

<Third_z>Some text</Third_z>

<ab>Some text</ab>

<xyz>

<xxx>10323</xxx>

<yyy>ID</yyy>

<zzz>nal</zzz>

<aaa>USA</aaa>

<bbb>Something for </bbb>

</xyz>

<xyz>

<xxx>10323</xxx>

<yyy>ugI</yyy>

<zzz>xtal</zzz>

<aaa>Canada</aaa>

<bbb>Something for </bbb>

</xyz>

</Third>

</Second>

</First>

I have to remove the entire ParentNode(<xyz>) if <aaa> has Canada text in it. The non matching <xyz> should still remain in the document.

I tried with node.getParentNode().removeChild(node);

But it didn't work.

Kindly help.

Thanks in advance.

[1082 byte] By [srins_2000a] at [2007-11-27 4:45:24]
# 1
create a new XML document without undesirable elements.
java_2006a at 2007-7-12 9:57:46 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 2

Here is my sample code & I get the following error:

org.w3c.dom.DOMException: NOT_FOUND_ERR: An attempt is made to reference a node in a context where it does not exist

try {

DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();

DocumentBuilder d = dbf.newDocumentBuilder();

Document xmldocument = d.parse(new File("abc.xml"));

NodeList entitlement_Node = xmldocument.getElementsByTagName("sample");

System.out.println("BEFORE AL : "+entitlement_Node);

for(int p = 0; p < entitlement_Node.getLength(); p++) {

Element ent_Nd = (Element)entitlement_Node.item(p);xmldocument.removeChild(ent_Nd.getElementsByTagName("sample_type").item(0).getParentNode());

}

}catch(Exception e) {}

srins_2000a at 2007-7-12 9:57:46 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 3
The command "node.getParentNode().removeChild(node);" does work if "node" refers to the proper node. You can use the following XPath expression to set reference to the node you specified:"/First/Second/Third/xyz[aaa='Canada']"
prgguya at 2007-7-12 9:57:46 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...