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:

Raum114

Mitglied
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);
    }
 
Ähnliche Java Themen
  Titel Forum Antworten Datum
V XML Newlines entfernen XML & JSON 5
wofus JSON filtern nach bestimmten Wert XML & JSON 7
Q Konvertierung von json zum Java Objekt nach vorgegebenem Schema XML & JSON 3
R Handler-Wechsel, SAX Parser bricht nach 8192 Byte ab XML & JSON 5
K Docbook tranformieren nach LaTeX XML & JSON 2
sylo Nach Export wird SAXParseException nicht mehr geworfen XML & JSON 4
T XPath Problem: finden einer Node nach Attributswert XML & JSON 2
N xml nach Value durchsuchen XML & JSON 8
W String nach XML nach String verwandeln XML & JSON 4
D XML nach BME Cat Norm prüfen? XML & JSON 4
I Editor, der nur Elemente einfuegt, die nach xsd zulaessig XML & JSON 2
S leading whitespaces nach einem XMLOutputter XML & JSON 9
A Point2D.double nach XML XML & JSON 2
A html-File nach txt-File konvertieren XML & JSON 15
T Newbie Frage. CSS Stylesheet einlesen und suchen nach Tags XML & JSON 6
A Auf der Suche nach Bibliotheken oder wie parsen? XML & JSON 15
M RSS nach WML XML & JSON 9
V Datenverlust nach sortieren (nur beim serialisieren) XML & JSON 4
H Nach einem Attribut suchen und dann löschen XML & JSON 3
M jaxb binding nach set XML & JSON 9
D Aus lesen einer XML-Datei ( 1 root, 3 childs) XML & JSON 7
G Nodes in Document kopieren, nur die Childs, die noch nicht existieren XML & JSON 7

Ähnliche Java Themen

Neue Themen


Oben