How to remove a child from from a node using jdom in java?

前端 未结 3 496
名媛妹妹
名媛妹妹 2021-01-15 01:23

I have a xml structure as follows:


    enabled
    

        
相关标签:
3条回答
  • 2021-01-15 01:31

    If you have the parent element rurl you can remove its children using the method removeChild or removeChildren.

    0 讨论(0)
  • 2021-01-15 01:40

    Use removeChild()

    http://download.oracle.com/javase/1.5.0/docs/api/org/w3c/dom/Node.html#removeChild(org.w3c.dom.Node)

    0 讨论(0)
  • 2021-01-15 01:45

    You'll need to do this:

    List<Element> elements = new ArrayList<Element>();
    
    while (subchilditr.hasNext()) {
        Element subchild = (Element) subchilditr.next();
        if (subchild.getText().equalsIgnoreCase(text)) {
            elements.add(subchild);
        }
    }
    
    for (Element element : elements) {
        element.getParent().removeContent(element);
    }
    

    If you try to remove an element inside of the loop you'll get a ConcurrentModificationException.

    0 讨论(0)
提交回复
热议问题