Example usage for org.jdom2.output XMLOutputter setFormat

List of usage examples for org.jdom2.output XMLOutputter setFormat

Introduction

In this page you can find the example usage for org.jdom2.output XMLOutputter setFormat.

Prototype

public void setFormat(Format newFormat) 

Source Link

Document

Sets the new format logic for the XMLOutputter.

Usage

From source file:utils.ParserXML.java

License:Apache License

public String getStringedSubTree(String element) throws JDOMException, IOException {
    String s = "";
    Element elem = rootElement.getChild(element);
    Iterator lst = elem.getDescendants();
    int i;/*from w ww .j  a  va 2s . com*/
    Element e = document.detachRootElement();
    e.removeNamespaceDeclaration(Namespace.NO_NAMESPACE);
    Element e2 = e.getChild(element);
    XMLOutputter xout = new XMLOutputter();
    Format f = Format.getPrettyFormat();
    xout.setFormat(f);
    return ((xout.outputString(e2).replaceAll("<" + element + ">", "")).replaceAll("</" + element + ">", ""));
}

From source file:view.MobilePartnerView.java

public boolean createXML(String url, String user, String driver, String password) throws Exception {
    Element root = new Element("dbconf");
    Document doc = new Document();

    Element child1 = new Element("url");
    // child1.addContent("jdbc:mysql://localhost:3306/mobile_partner");
    child1.addContent(url);/*from  w  ww .  j a  v  a  2 s .  c o  m*/
    child1.setAttribute("name", "javax.persistence.jdbc.url");

    Element child2 = new Element("user");
    // child2.addContent("root");
    child2.addContent(user);
    child2.setAttribute("name", "javax.persistence.jdbc.user");

    Element child3 = new Element("driver");
    //child3.addContent("com.mysql.jdbc.Driver");
    child3.addContent(driver);
    child3.setAttribute("name", "javax.persistence.jdbc.driver");

    Element child4 = new Element("password");
    //  child4.addContent("nbuser");
    child4.addContent(password);
    child4.setAttribute("name", "javax.persistence.jdbc.password");

    root.addContent(child1);
    root.addContent(child2);
    root.addContent(child3);
    root.addContent(child4);

    doc.setRootElement(root);

    XMLOutputter outter = new XMLOutputter();
    outter.setFormat(Format.getPrettyFormat());
    outter.output(doc, new FileWriter(new File(dir + "\\dbconf.xml")));
    File xmlFile = new File(dir + "\\dbconf.xml");
    if (xmlFile.exists()) {
        return true;
    } else {
        return false;
    }
}

From source file:wasr.actions.SaveDocAction.java

License:Apache License

@Override
public void actionPerformed(ActionEvent actionEvent) {

    File file = new File(WASRFrame.getInstance().getCurrentReport().getReportFolder(), "report.xml");

    Document wasrDoc = WASRFrame.getInstance().getCurrentReport().getReportDOM();

    try {/*from  w  ww .  j a  v a2s.c o m*/
        if (!file.exists()) {
            file.createNewFile();
        }
        FileOutputStream fos = new FileOutputStream(file);
        BufferedOutputStream bos = new BufferedOutputStream(fos);
        XMLOutputter outputter = new XMLOutputter();
        outputter.setFormat(Format.getPrettyFormat());
        outputter.output(wasrDoc, bos);
        bos.flush();
        fos.close();
    } catch (IOException e) {
        e.printStackTrace(); // TODO: push save errors up to UI.
    }
}

From source file:XML.JXML.java

public void CreateXML() {

    try {//w  w w .  java  2 s. c om
        Element root = new Element("DriveLessons");
        Document doc = new Document();

        Element stdnt = new Element("Student");
        stdnt.addContent(new Element("StudentName").addContent(studentName));
        stdnt.addContent(new Element("PermitNumber").addContent(studentPermitNumber));
        stdnt.addContent(new Element("DateOfBirth").addContent(studentDOB));

        Element instr = new Element("Instructor");
        instr.addContent(new Element("InstructorName").addContent(instructorName));
        instr.addContent(new Element("InstructorID").addContent(instructorID));

        Element eval = new Element("Evaluation");
        eval.addContent(new Element("EvaluationDate").addContent(evaluationDate));
        eval.addContent(new Element("Pass").addContent(getFinalGrade()));

        root.addContent(stdnt);
        root.addContent(instr);
        root.addContent(eval);

        doc.setRootElement(root);

        XMLOutputter outter = new XMLOutputter();
        outter.setFormat(Format.getPrettyFormat());
        outter.output(doc, new FileWriter(new File("C:\\temp\\myxml.xml")));
    } catch (IOException ex) {
        Logger.getLogger(JXML.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:xmlwriter.XmlWriter.java

/**
 * Es usado para leer el nombre de el archivo que posteriormente ser escrito en un archivo con extension .xml
 * @param doc Documento Generado despues de la interaccion con el usuario y que ser escrito en un archivo con extension xml.
 * @return booleano que indica si encontraron errores al momento de escribir el archivo en el disco. Devuelve true si el archivo se guardo con exito y false de lo contrario.
 *///from w  w  w. jav a 2 s . c om
private static boolean saveDocument(Document doc) {

    try {
        String fileName = "";
        System.out.print("Nombre del archivo XML (sin la extensin): ");
        fileName = read.readLine();

        XMLOutputter xmlOutput = new XMLOutputter();
        xmlOutput.setFormat(Format.getPrettyFormat());
        xmlOutput.output(doc, new FileWriter(fileName + ".xml"));
        return (true);
    } catch (IOException ex) {
        Logger.getLogger(XmlWriter.class.getName()).log(Level.SEVERE,
                "Error al escribir el archivo - saveDocument", ex);
        return (false);
    }

}