Example usage for org.dom4j Document remove

List of usage examples for org.dom4j Document remove

Introduction

In this page you can find the example usage for org.dom4j Document remove.

Prototype

boolean remove(Node node);

Source Link

Document

Removes the given Node if the node is an immediate child of this branch.

Usage

From source file:ch.javasoft.xml.config.XmlConfig.java

License:BSD License

/**
 * Parses the given document and returns an XmlConfig instance. Note that
 * this document is expected to contain an application element (direct child
 * of root element) with a name attribute and possible with arg child nodes.
 * Such a document is usually received by calling {@link #toXmlDocument()}.
 *//*from   w  w w  .j  ava 2 s. c o m*/
@SuppressWarnings("unchecked")
public static XmlConfig fromXmlDocument(Document doc) {
    final Element app = doc.getRootElement().element(XmlElement.application.getXmlName());
    final String appName = app.attributeValue(XmlAttribute.name.getXmlName());
    final List<String> args = new ArrayList<String>();
    final Iterator<Element> it = app.elementIterator(XmlElement.arg.getXmlName());
    while (it.hasNext()) {
        args.add(it.next().attributeValue(XmlAttribute.value.getXmlName()));
    }
    doc.remove(app);
    return new XmlConfig(appName, doc, args.toArray(new String[args.size()]));
}

From source file:fr.gouv.vitam.xml.XmlDom4jTools.java

License:Open Source License

public final static void removeEmptyDocument(Document doc) {
    @SuppressWarnings("unchecked")
    Iterator<Node> nodes = doc.nodeIterator();
    List<Attribute> toremove = new ArrayList<>();
    while (nodes.hasNext()) {
        Node node = (Node) nodes.next();
        if (node instanceof Element) {
            removeEmptyElement((Element) node);
        } else if (node instanceof Attribute) {
            if (((Attribute) node).getValue().length() == 0) {
                toremove.add(((Attribute) node));
            }//from   w ww .jav  a 2 s .co m
            //removeEmptyAttribute((Attribute) node);
        }
    }
    for (Attribute attribute : toremove) {
        doc.remove(attribute);
    }
    toremove.clear();
}

From source file:org.codehaus.cargo.container.weblogic.WebLogic8xConfigXmlInstalledLocalDeployer.java

License:Apache License

/**
 * {@inheritDoc} undeploys files by removing their configuration to the config.xml file of the
 * WebLogic server.// w w w  .  j  a  v  a  2  s. c  o  m
 * 
 * @see org.codehaus.cargo.container.spi.deployer.AbstractDeployer#undeploy(org.codehaus.cargo.container.deployable.Deployable)
 */
@Override
public void undeploy(Deployable deployable) {
    Document configXml = readConfigXml();
    XPath xpathSelector = DocumentHelper.createXPath(
            "//Application[@Path='" + getFileHandler().getParent(getAbsolutePath(deployable)) + "']");
    List<Element> results = xpathSelector.selectNodes(configXml);
    for (Element element : results) {
        configXml.remove(element);
    }
    this.writeConfigXml(configXml);

}

From source file:org.openxml4j.opc.signature.RelationshipTransform.java

License:Apache License

public static void RemoveAllTopLevelComments(Document doc) {
    List<Node> tobeRemovedNodes = new Vector<Node>();
    for (int i = 0; i < doc.nodeCount(); i++) {
        if (doc.node(i).getNodeType() == Document.COMMENT_NODE)
            tobeRemovedNodes.add(doc.node(i));
    }//from  w w  w.  ja v  a2 s  . co  m

    for (Node tempNode : tobeRemovedNodes) {
        doc.remove(tempNode);
    }
}