Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Empfohlene Antworten

Veröffentlicht

Hallo, ich habe eine XML-Datei nach folgendem Schema:

<?xml version="1.0" encoding="utf-8" ?>

<Netz xmlns="http://tempuri.org/Netz.xsd">

<DatenTable>

<SchuelerId>0</SchuelerId>

<DiensstellenID>471100</DiensstellenID>

</DatenTable>

<DatenTable>

<SchuelerId>1</SchuelerId>

<DiensstellenID>3536546</DiensstellenID>

</DatenTable>

</Netz>

Und nun möchte ich jeden Datentable noch einen neuen Tag hinzufügen. So das die XML am Ende folgendermaßen aussieht:

<?xml version="1.0" encoding="utf-8" ?>

<Netz xmlns="http://tempuri.org/Netz.xsd">

<DatenTable>

<SchuelerId>0</SchuelerId>

<DiensstellenID>471100</DiensstellenID>

<Name>Heinz</Name>

</DatenTable>

<DatenTable>

<SchuelerId>1</SchuelerId>

<DiensstellenID>3536546</DiensstellenID>

<Name>Heinz</Name>

</DatenTable>

</Netz>

ich habe es schon probiert, allerdings ohne erfolg.

Element root = doc.getRootElement();

List<Element> elemL = root.getChildren();

for (Element e : elemL) {

Element Name = new Element("Name");

Name.addContent("Heinz");

e.addContent(Name);

}

natürlich sollt nicht jedes Datentable den Namen "heinz" bekommen, ist nur der einfachheit halber grad so gemacht... problem an der sache ist einfach, dass er keinen fehler ausspuckt, aber auch einfach gar nichts passiert. die xml datei sieht genauso aus wie vorher.

hat jemand ne idee?

Bearbeitet von _Toni_

Ja, die ganze Sache wird in eine "Temp-XML" gespeichert. Ich möchte auch nur dort die Änderung. Die original XML soll erhalten bleiben.

String xmlCopy = originalXML.substring(0, originalXML.length() - 4)

+ ".temp";

SAXBuilder builder = new SAXBuilder();

Document doc = builder.build(new File(originalXML)); // xmlCopy

Element root = doc.getRootElement();

List<Element> elemL = root.getChildren();

for (Element e : elemL) {

Element Name = new Element("Name");

Name.addContent("Heinz");

e.addContent(Name);

}

XMLOutputter output = new XMLOutputter();

FileOutputStream out = new FileOutputStream(xmlCopy);

output.output(doc, out);

out.flush();

out.close();

also die ganze Sache funktioniert nun doch. Und zwar genau so wie sie da steht... :)

Erstelle ein Konto oder melde dich an, um einen Kommentar zu schreiben.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.