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.

XML Dokument Splitten

Empfohlene Antworten

Hallo zusammen!

ich stehe vor einen Problem, bei dem ich nicht mehr weiterkomme.

Ich habe eine xml-Datei im Format:



<Freight Data>

  <TransportDocument>

        .....

  </TransportDocument>

  <TransportDocument>

        .....

  </TransportDocument>

  <TransportDocument>

        .....

  </TransportDocument>

   .

   .

   .

</Freight Data>


Pro TransportDocument soll jetzt ein eigenes Dokument erstellt werde im Format:

<Freight Data>

  <TransportDocument>

        .....

  </TransportDocument>

</Freight Data>

Ich habe das so gelößt, dass ich mit dem DomParser erstmal alle Transport-Dokumente auslese, und mir die resultierende NodeList erstmal merke. Anschliessend kopiere ich dann die Ursprungs-Datei NodeList.getLenght() mal. Lösche alle ChildNodes und versuche dann jeweils ein Transport Document pro File wieder anszuhängen. Das sieht dann so aus:


private void createDocumentCopies() throws Exception{

	int i;

	String tempFileName;

	File tempFile;

    for (i = 0; i < transportDocuments.getLength(); i++) {

	    documentCounter++;


	    tempFile = copyFile(file);


        DOMParser tempParser = new DOMParser();

        tempParser.parse(new InputSource(new FileReader(tempFile)));

        Document tempDoc = tempParser.getDocument();


		removeAllChildNodes(tempDoc.getElementsByTagName(FREIGHT_DATA_TAG).item(0));


		Node tempNode = transportDocuments.item(i);

		tempDoc.getElementsByTagName(FREIGHT_DATA_TAG).item(0).appendChild(tempNode); //hier tritt der Fehler auf


		writeXml(tempDoc);

    }


}


Mein Problem ist jetzt, dass beim appendChild() folgeden Exception auftritt:

com.ibm.xml.dom.DOMExceptionImpl

	java.lang.Throwable(java.lang.String)

	java.lang.Exception(java.lang.String)

	java.lang.RuntimeException(java.lang.String)

	org.w3c.dom.DOMException(short, java.lang.String)

	com.ibm.xml.dom.DOMExceptionImpl(short, java.lang.String)

	org.w3c.dom.Node com.ibm.xml.dom.NodeImpl.insertBefore(org.w3c.dom.Node, org.w3c.dom.Node)

	org.w3c.dom.Node com.ibm.xml.dom.NodeImpl.appendChild(org.w3c.dom.Node)

.

.

.


Hat irgendjemand eine Idee, warum das nicht funktioniert???

Vielen Dank.

Gruß

Mirko

Ich geb mir mal selber die Antwort...

man muß die Node erst im anderen Document mit import(aNode, true); importierten die daraus folgende Node kann man dann anhängen...

Das geht ;)

Archiv

Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.

Konto

Navigation

Suchen

Suchen

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.