dom4j xml 添加一个节点,指点位置添加节点

http://www.cnblogs.com/yesun/archive/2009/03/16/1413559.html

Element elemBbody = (Element)objXml.selectSingleNode("//body");
      if(elemBbody == null)
       elemBbody = objXml.getRootElement();
      List elements = elemBbody.content();
      List listRadioByName = objXml.selectNodes("//input[@type='checkbox' and @name='"+objName+"']");

      //插入节点到指定位置
      elements.add(elements.indexOf(listRadioByName.get(0)),elemSelect);
      elemBbody.setContent(elements);




            Element element = doc.getRootElement();
            Element responseCodeElement =element.addElement("responseCode");
            responseCodeElement.setText(FAILRESPONSECODE);

你可能感兴趣的:(dom4j)