Hallo,
ich erzeuge eine XML-Datei.
Problem ist, das für das Element "optionen" ein Attribut "xmlns" mit leeren Inhalt erzeugt wird. Dieses leere "xmlns" Attribut wird nur bei Elementen erzeugt, die direkt am "root"-Element hängen.
Es sollte eher so aussehen:
Wie kann man das realisieren???
Vielen Dank im Voraus
Marcus
ich erzeuge eine XML-Datei.
Code:
Element root = new Element("DatML-RAW-D");
root.setNamespace(Namespace.getNamespace("http://www.destatis.de/schema/datml-raw/2.0/de"));
root.setAttribute("version", "2.0");
// Optionen hinzufügen
Element optionen = new Element("optionen");
// kennung=200 => Daten werden nach Eingangs- und Vorprüfung beim Berichtsempfänger verworfen
Element test = new Element("test");
test.setAttribute("kennung", "200");
optionen.addContent(test);
root.addContent(optionen);
// Dokument speichern
String outfile = "test.xml";
Document doc = new Document(root);
// Damit das XML-Dokument schoen formattiert wird holen wir uns ein Format
Format format = Format.getPrettyFormat();
// und setzen das encoding, da auch Umlaute vorkommen koennten.
format.setEncoding("iso-8859-1");
// Erzeugung eines XMLOutputters dem wir gleich unser Format mitgeben
XMLOutputter out = new XMLOutputter(format);
System.out.println(out.getFormat().getEncoding());
FileWriter fw = new FileWriter(new File(outfile));
out.output( doc, fw);
Code:
<optionen xmlns="">
<test kennung="200" />
</optionen>
Code:
<optionen>
<test kennung="200" />
</optionen>
Vielen Dank im Voraus
Marcus