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 zusammen.

Ich bin momentan dabei ein HTML-Dokument zu filtern. Filtern bedeutet, dass nur bestimmte Elemente aus dem HTML-Dokument extrahiert werden. Diese Elemente möchte ich jetzt in ein neues Dokument importieren bzw adoptieren. Jedoch funktioniert keins von beidem.

Erstmal mein Code:


Document domDoc = builder.newDocument();

Element tempHtmlBlockElement = domDoc.createElement("html");

domDoc.appendChild(tempHtmlBlockElement);

List<Node> rubrikNodes 	= new ArrayList<Node>();

List<Node> ausgabeNodes = new ArrayList<Node>();


... Fülle die Liste, das Filtern funktioniert und ich erhalte auch alle enthaltenen Elemente ...

...

 for(Node tempNode : rubrikNodes) {



//Beim Versuch die Node zu importieren, schmeißt mir Java eine 

//"org.w3c.dom.DOMException: DOM method not supported" Exception

        	Node clonedTempNodeAdopted = domDoc.importNode(tempNode, true); 


//Versuche ich die Node zuerst zu Clonen und dann dem neuen Dokument "zuzuweisen" durch "adoptNode", 

//bekomme ich eine null-Node als Ergebnis der "adoptNode"-Funktion. Lasse ich das adoptNode weg, wird eine 

//"WRONG_DOCUMENT_ERR: A node is used in a different document than the one that created it." -Exception geworfen. 

// Was auch korrekt ist...

                Node clonedTempNode = tempNode.cloneNode(true);

                clonedTempNode = domDoc.adoptNode(clonedTempNode);

        	tempHtmlBlockElement.appendChild(clonedTempNode);


        }


 for(Node tempNode : ausgabeNodes) {

        	...

        }


Jetzt meine Frage, mache ich etwas falsch?

Ich benutze JDK6 (1.6.0_17 bzw 1.6.0_30). Könnte es vielleicht auch daran liegen? Oder sollte ich eine andere Dom-Implementierung benutzen?

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.