How do I remove a node element by id in XML?

后端 未结 2 1818
醉酒成梦
醉酒成梦 2021-01-21 11:12

Using: javax.xml and org.w3c:

public void removeNodeFromXML(File xmlfile_, String uuid)
  {
    DocumentBuilderFactory factory = Docume         


        
2条回答
  •  情书的邮戳
    2021-01-21 11:51

    You can use:

    Element element = doc.getElementById("1236");
    element.getParentNode().removeChild(element);
    

    This should give you the element with ID "1236". You then get the parent node for the element and remove the element by passing the element with ID "1236" to removeChild.

    See here for a full example.

    Hope this helps.

提交回复
热议问题