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 nodelists 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

Popular posts from this blog

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.Error occurred in starting fork -

windows - Debug iNetMgr.exe unhandle exception System.Management.Automation.CmdletInvocationException -

configurationsection - activeMq-5.13.3 setup configurations for wildfly 10.0.0 -