K
Ksou
I need to copy a node from tree A to tree B. And then export tree B as image
by an API org.apache.batik.transcoder.image.JPRGTranscoder. But I got a
strange thing that the exported image does not have expected effect. But I
can get the manipulated one when I export it as XML file by
javax.xml.transform.Transformer.
I want to know is there any method I need to invoke after dom manipulated
for making manipulation effective.
Here is the code for manipulating the tree:
.....
DocumentBuilderFactory documentBuilderFactory =
DocumentBuilderFactory.newInstance();
documentBuilderFactory.setNamespaceAware(true);
Document document = documentBuilderFactory.newDocumentBuilder().parse(new
StringBufferInputStream(xmlString));
Document originalDocument =
documentBuilderFactory.newDocumentBuilder().parse(new
File("C:\\sample.svg"));
// remove a node
Element manipulatedGroupElement =
originalDocument.getElementById("manipulatedGroup");
Node manipulatedGroupParentNode = manipulatedGroupElement.getParentNode();
manipulatedGroupParentNode.removeChild(manipulatedGroupElement);
// add a new node which is copied from anther tree
Node clonedNode =
originalDocument.importNode(document.getElementById("manipulatedGroup"),true
);
manipulatedGroupParentNode.appendChild(clonedNode);
.....
by an API org.apache.batik.transcoder.image.JPRGTranscoder. But I got a
strange thing that the exported image does not have expected effect. But I
can get the manipulated one when I export it as XML file by
javax.xml.transform.Transformer.
I want to know is there any method I need to invoke after dom manipulated
for making manipulation effective.
Here is the code for manipulating the tree:
.....
DocumentBuilderFactory documentBuilderFactory =
DocumentBuilderFactory.newInstance();
documentBuilderFactory.setNamespaceAware(true);
Document document = documentBuilderFactory.newDocumentBuilder().parse(new
StringBufferInputStream(xmlString));
Document originalDocument =
documentBuilderFactory.newDocumentBuilder().parse(new
File("C:\\sample.svg"));
// remove a node
Element manipulatedGroupElement =
originalDocument.getElementById("manipulatedGroup");
Node manipulatedGroupParentNode = manipulatedGroupElement.getParentNode();
manipulatedGroupParentNode.removeChild(manipulatedGroupElement);
// add a new node which is copied from anther tree
Node clonedNode =
originalDocument.importNode(document.getElementById("manipulatedGroup"),true
);
manipulatedGroupParentNode.appendChild(clonedNode);
.....