1

I want to use JavaFX WebView as XML viewer. I want to manage the XML Documents and not have to load each through the WebView as string, but use pre-loaded XML (DOM) Documents.

  1. So basically doing the equivalent to the missing functionality webEngine.setDocument(doc). I want to control the DOM Document so I can dynamically make changes, attach events etc, which works fine, but is all lost on reloading the XML with webEngine.loadContent(String) and getDocument().

  2. If this is really not possible, alternatively as work around, I can load a blank XML using:

    webEngine.loadContent("", "text/xml");

then use getDocument() to get the top node. This works ok so far and (after completion) I obtain an empty but apparently valid XML Document. How can I add a child to this, specifically assign the top element from my existing Document? I've tried things like:

webEngine.getDocumentElement().appendChild(newdoc.getDocumentElement());

or

webEngine.getDocumentElement().appendChild(newdoc.getDocumentElement().getFirstChild());

where newdoc is one of my existing DOM Documents. This and other variations always result in ClassCastException: com.sun.org.apache.xerces.internal.dom.DeferredElementNSImpl cannot be cast to com.sun.webkit.dom.NodeImpl

Thank you, I appreciate any help!

Yost777
  • 597
  • 1
  • 6
  • 19
  • https://stackoverflow.com/questions/12073356/force-java-to-open-xml-in-web-browser – SedJ601 Jun 25 '18 at 13:18
  • Sedrick: Thanks for the response, however I have no problem loading an XML, but as I described in my question, I want to show an existing DOM Document rather than loading using webEngine.loadContent(String) or from Uri. – Yost777 Jun 25 '18 at 13:23
  • [How to create a Minimal, Complete, and Verifiable example](https://stackoverflow.com/help/mcve) – SedJ601 Jun 25 '18 at 13:25
  • 1
    The property for `Document` is read-only so I don't believe this is possible. I tried looking at the source code to see if this could be "hacked" via reflection but the implementation seems too specialized to get this to work. – Slaw Jun 25 '18 at 14:32
  • Slaw: Thanks for the response and exploring this, too bad the API doesn't expose such function. – Yost777 Jun 25 '18 at 14:39

0 Answers0