Newlines nach childs erste ebene (dom)

ich2

Mitglied
Hallo,
ich brauche eine xml die dieses format hat:
<parent>
<child><bla>sdsdfs</bla><blup>afdafs</blup></child>
<child><bla>sdsdfs</bla><blup>afdafs</blup></child>
<child><bla>sdsdfs</bla><blup>afdafs</blup></child>
...
</parent>

also für jedes child unter parent eine neue zeile, aber keine intends, und die kinder von child sollen alle in der selben zeile stehen.

Das xml an sich erstelle ich schon, aber ich weiß nicht wie ich das Format so hinbekomme.

Kann mir bitte jemand helfen?
 
Zuletzt bearbeitet:
Versuchs mal damit aber halt mit INDENT auf "no". Falls es nicht in ein File geschrieben werden soll kannst du es ja modifizieren.

Java:
    /**
     * This method writes a document to a file.
     * @param doc The document to be written.
     * @param filename The name of the file to be created.
     */
    public void writeXmlFile(Document doc, String filename) throws Exception {
        // Prepare the DOM document for writing
        Source source = new DOMSource(doc);
        // Prepare the output file
        File file = new File(filename);
        Result result = new StreamResult(file);
        // Write the DOM document to the file
        Transformer xformer = TransformerFactory.newInstance().newTransformer();
        xformer.setOutputProperty(OutputKeys.INDENT, "yes");
        xformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
        xformer.transform(source, result);
    }
 

Zurück
Oben