You are viewing a plain text version of this content. The canonical link for it is here.
Posted to batik-users@xmlgraphics.apache.org by fr...@pandora.be on 2004/09/03 15:02:53 UTC
Replacing svg nodes
Hi,
I would like to replace a specific node in a rendered svg with a node from another (physical) document. This is the code peformed in the updatemanager thread. The 'doc' is the SVGDocument of the rendered canvas. The svgFragment is the node of another svg file, I want to use to replace the old one with.
DocumentFragment df = doc.createDocumentFragment();
Element fragment = svgFragment.getFragment();
df.appendChild(fragment);
Node fragmentOK = doc.importNode(df, false);
Element el = doc.getElementById("replace");
el.getParentNode().replaceChild(fragmentOK, el);
I get the following error:
org.w3c.dom.DOMException: The given node (type: 11, name: #document-fragment) was not created by the current document.
at org.apache.batik.dom.AbstractNode.createDOMException(AbstractNode.java:404)
at org.apache.batik.dom.AbstractParentNode.checkAndRemove(AbstractParentNode.java:465)
at org.apache.batik.dom.AbstractParentNode.appendChild(AbstractParentNode.java:228)
at com.saudiaramco.mapboard.presentation.commands.PreferenceCommand$Updater.run(PreferenceCommand.java:55)
at org.apache.batik.util.RunnableQueue.run(Unknown Source)
at java.lang.Thread.run(Thread.java:534)
---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xml.apache.org
For additional commands, e-mail: batik-users-help@xml.apache.org
Re: Replacing svg nodes
Posted by Thomas DeWeese <Th...@Kodak.com>.
Hi Frederik,
The problem is that you don't import the 'fragment'
into doc before appending it to the document fragment.
You want something like:
Element fragment = svgFragment.getFragment();
fragment = doc.importNode(fragment, true);
Element el = doc.getElementById("replace");
el.getParentNode().replaceChild(fragmentOK, el);
No need to involve document fragment.
frederik.santens@pandora.be wrote:
> Hi,
>
> I would like to replace a specific node in a rendered svg with a node from another (physical) document. This is the code peformed in the updatemanager thread. The 'doc' is the SVGDocument of the rendered canvas. The svgFragment is the node of another svg file, I want to use to replace the old one with.
>
> DocumentFragment df = doc.createDocumentFragment();
> Element fragment = svgFragment.getFragment();
> df.appendChild(fragment);
>
> Node fragmentOK = doc.importNode(df, false);
> Element el = doc.getElementById("replace");
> el.getParentNode().replaceChild(fragmentOK, el);
>
> I get the following error:
> org.w3c.dom.DOMException: The given node (type: 11, name: #document-fragment) was not created by the current document.
> at org.apache.batik.dom.AbstractNode.createDOMException(AbstractNode.java:404)
> at org.apache.batik.dom.AbstractParentNode.checkAndRemove(AbstractParentNode.java:465)
> at org.apache.batik.dom.AbstractParentNode.appendChild(AbstractParentNode.java:228)
> at com.saudiaramco.mapboard.presentation.commands.PreferenceCommand$Updater.run(PreferenceCommand.java:55)
> at org.apache.batik.util.RunnableQueue.run(Unknown Source)
> at java.lang.Thread.run(Thread.java:534)
>
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: batik-users-unsubscribe@xml.apache.org
> For additional commands, e-mail: batik-users-help@xml.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xml.apache.org
For additional commands, e-mail: batik-users-help@xml.apache.org