JavaFX WebView importNode

时间:2014-06-27 10:26:12

标签: java svg javafx

我使用WebView显示SVG图像,并且我想将另一个SVG图像添加为原始SVG的一个节点的子节点(类似于此处使用batik:How do I superimpose one SVG image onto another using Apache Batik?所描述的内容)。然后我得到一个ClassCastException。
这是我使用基本SVG图像的地方:

final String svg = "background.svg";
final uri = Paths.get(svg).toAbsolutePath().toUri();
WebView root = new WebView();
root.getEngine().load(uri.toString());

SVG正确显示。
然后我有这段代码,在用户按下按钮时执行,试图将另一个图像添加到父SVG:

File anotherFile = new File("over.svg");
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder dBuilder = dBuilder = dbFactory.newDocumentBuilder();
Document doc = dBuilder.parse(anotherFile);

Node e = root.getEngine().getDocument().importNode(doc.getDocumentElement(), true);
root.getEngine().getDocument().appendChild(e);

尝试使用importNode时出现以下异常:

java.lang.ClassCastException:
com.sun.org.apache.xerces.internal.dom.DeferredElementImpl cannot be cast to
com.sun.webkit.dom.NodeImpl

0 个答案:

没有答案
相关问题