Example usage for org.jdom2 Document removeContent

List of usage examples for org.jdom2 Document removeContent

Introduction

In this page you can find the example usage for org.jdom2 Document removeContent.

Prototype

@Override
    public Content removeContent(int index) 

Source Link

Usage

From source file:org.isima.carsharing.launcher.Launcher.java

public static void addConfigComment(SettingsDelegate settingsDelegate, File out) {
    try {/*ww  w.jav a 2  s  .  c  o m*/
        SAXBuilder builder = new SAXBuilder();

        Document doc = (Document) builder.build(out);
        Element rootNode = doc.getRootElement();
        Element rootNodeCopy = rootNode.clone();

        doc.removeContent(rootNode);
        rootNodeCopy.detach();

        Comment comment = new Comment(settingsDelegate.usedConfigsToXMLComment());
        doc.addContent(comment);
        doc.addContent(rootNodeCopy);

        XMLOutputter xmlOutput = new XMLOutputter();
        xmlOutput.setFormat(Format.getPrettyFormat());
        xmlOutput.output(doc, new FileWriter(out));
    } catch (JDOMException | IOException ex) {
        Logger.getLogger(Launcher.class.getName()).log(Level.SEVERE, null, ex);
    }
}