dom - Delete XML child node -
hi having trouble in deleting xml node.
<instance> <internal> <attribute> <name>length</name> </attribute> <name>internal</name> </internal> <name>instanec</name> </instance>
i want delete name node output below.
<instance> <internal> <attribute> </attribute> </internal> </instance>
i tried following code :
nodelist baseelmntlst2 = doc.getelementsbytagname("name"); (int k = 0; k < baseelmntlst2.getlength(); k++) { element node = (element) baseelmntlst2.item(k); element node2 = (element) baseelmntlst2.item(k).getparentnode(); node2.removechild(node);
}
but not delete name elements dont understand.
thankyou
dom nodelist
s live collections if want delete items in nodelist
1 way start @ end e.g. for (int k = baseelmntlst2.getlength(); k >= 0; k--)
. or use while (baseelmntlst2.getlength() > 0) baseelmntlst2.item(0).getparentnode().removechild(baseelmntlst2.item(0));
.
Comments
Post a Comment