Hallo!
Ich habe Probleme beim Erzeugen einen XML -File.
1- Die Unterelemente sind nicht richtig sortiert
2- Meine XML-File ist nicht richtig Formatiert: Der XML-File ist eine lange Zeile ohne Zeile Einbruch.
Meine Code sieht so aus:
kann mir jemand helfen?
Danke für jede Hilfe.
Ich habe Probleme beim Erzeugen einen XML -File.
1- Die Unterelemente sind nicht richtig sortiert
Code:
<SAM_XML><gesamtDemand><ArrivalDemend /><DepartureDemend /><GesamtDemend /><Value>42.0</Value>...
2- Meine XML-File ist nicht richtig Formatiert: Der XML-File ist eine lange Zeile ohne Zeile Einbruch.
Meine Code sieht so aus:
Code:
SAXBuilder builder = new SAXBuilder();
Element xml = new Element("SAM_XML");
Document doc = xml.getDocument();
Element Demand = new Element("Demand");
Element aDemand = Demand.addContent(new Element("ArrivalDemand"));
aDemand.setName("arrivalDemand");
Element dDemand = Demand.addContent(new Element("DepartureDemand"));
dDemand.setName("departureDemand");
Element gDemand = Demand.addContent(new Element("GesamtDemand"));
gDemand.setName("gesamtDemand");
for (int i=0; i < window.getSize(); i++){
Result result = (Result)list.get(i);
Element aValue = new Element("Value");
aValue.setName("Value");
aValue.addContent(new Double(result.getArrivalDemand()).toString());
aDemand.addContent(aValue);
Element dValue = new Element("Value");
dValue.setName("Value");
dValue.addContent(new Double(result.getDepartureDemand()).toString());
dDemand.addContent(dValue);
Element gValue = new Element("Value");
gValue.setName("Value");
gValue.addContent(new Double(result.getBetriebsDemand()).toString());
gDemand.addContent(gValue);
}
xml.addContent(Demand);
try {
FileOutputStream out = new FileOutputStream(Constants.PATH_XML_OUTPUT);
XMLOutputter serializer = new XMLOutputter();
serializer.output(xml, out);
out.flush();
out.close();
}
catch (IOException e) {
System.err.println(e);
System.out.println("Fehler bei XML Parsen ");
}
}
Danke für jede Hilfe.