Example usage for org.jdom2 Element detach

List of usage examples for org.jdom2 Element detach

Introduction

In this page you can find the example usage for org.jdom2 Element detach.

Prototype

@Override
    public Element detach() 

Source Link

Usage

From source file:rodrigorar.data.IOManager.java

License:Open Source License

public void writeBookDatabaseDocument() throws InexistentBookException {
    Document document = new Document(new Element("Books"));
    Element rootElement = document.getRootElement();
    Map<String, Element> bookXMLMap = this.buildBookXMLObjects();
    Set<String> keySet = bookXMLMap.keySet();

    for (String key : keySet) {
        Element bookElement = bookXMLMap.get(key);
        bookElement.detach();
        rootElement.addContent(bookElement);
    }/*from   w  w w .  j  ava2s .com*/

    this.printDocument(this.buildFilePath(IOManager.BOOK_DB), document);
}

From source file:rodrigorar.data.IOManager.java

License:Open Source License

public void writeReadingFileDatabaseDocument() throws InexistentReadingFileException {
    Document document = new Document(new Element("ReadingFiles"));
    Element rootElement = document.getRootElement();
    Map<String, Element> readingFileXMLMap = this.buildReadingFileXMLObjects();
    Set<String> keySet = readingFileXMLMap.keySet();

    for (String key : keySet) {
        Element readingFileElement = readingFileXMLMap.get(key);
        readingFileElement.detach();
        rootElement.addContent(readingFileElement);
    }//w w  w  . j a va  2 s .  c om
    this.printDocument(this.buildFilePath(IOManager.READINGFILE_DB), document);
}

From source file:swing.xml.Form.java

@Override
public void actionPerformed(ActionEvent e) {
    //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    if (e.getSource() == Enter) {
        String String1 = Text1.getText();
        String String2 = Text2.getText();
        String String3 = Text3.getText();

        try {//from  w  ww . java2s.c o  m

            Element Lala = new Element("Texts");
            Lala.detach();
            Document doc = new Document(Lala);

            Element Element_Text1 = new Element("Text");
            Element_Text1.addContent(new Element("text_id").setText("1"));
            Element_Text1.addContent(new Element("text_content").setText(String1));

            doc.getRootElement().addContent(Element_Text1);

            Element Element_Text2 = new Element("Text");
            Element_Text2.addContent(new Element("text_id").setText("2"));
            Element_Text2.addContent(new Element("text_content").setText(String2));

            doc.getRootElement().addContent(Element_Text2);

            Element Element_Text3 = new Element("Text");
            Element_Text3.addContent(new Element("text_id").setText("3"));
            Element_Text3.addContent(new Element("text_content").setText(String3));

            doc.getRootElement().addContent(Element_Text3);

            // new XMLOutputter().output(doc, System.out);
            XMLOutputter xmlOutput = new XMLOutputter();

            // display nice nice
            xmlOutput.setFormat(Format.getPrettyFormat());
            xmlOutput.output(doc, new FileWriter("C:\\Users\\Alumno\\Desktop\\Text.xml"));

            System.out.println("File Saved!");
        } catch (IOException io) {
            System.out.println(io.getMessage());
        }

        System.out.println("Texto 1: " + String1);
        System.out.println("Texto 2: " + String2);
        System.out.println("Texto 3: " + String3);
        JOptionPane.showMessageDialog(null,
                "Texto 1: " + String1 + "\nTexto 2: " + String2 + "\nTexto 3: " + String3);
    }
}