Cameron McCormack,您好!
Thanks a lot for you reply, I think I get the answner from you.
======= 2009-03-09 07:13:54 您在来信中写道:=======
>杨莹:
>> I get have two svg document instances. the docA and docB, I want to
>> insert docA to docB, because I know SVG tag can be nested. so I code
>> followling:
>>
>> Node node = docA.getFirstChild();// the svg root element
>> docB.appendChild(node); // nest svg
>
>In this case you are lucky that the first child of the Document node is
>in fact the <svg> element. But this might not always be the case: you
>can have a Comment node before it, for example. It would be better to
>use
>
> Node node = docA.getDocumentElement();
>
>instead.
>
>> but I run the code and get the exception:
>>
>> org.w3c.dom.DOMException: The node (type: 1, name: svg) cannot be
>> inserted, since the document node already has a node of type 1.
>> at
>> org.apache.batik.dom.AbstractNode.createDOMException(AbstractNode.java:408)
>> at
>> org.apache.batik.dom.AbstractDocument.checkChildType(AbstractDocument.java:855)
>> at
>> org.apache.batik.dom.AbstractParentNode.checkAndRemove(AbstractParentNode.java:455)
>> at
>> org.apache.batik.dom.AbstractParentNode.appendChild(AbstractParentNode.java:203)
>>
>> why that exception happens? how can I fix it? thanks for reply.
>
>It’s because you are trying to append the <svg> element as a child of
>the Document node, and a Document node can have only one Element child
>(which is what the “type 1” means). Probably you want to append the
><svg> element as a child of the root <svg> in docB. Also, since ‘node’
>comes from a different document, you need to call importNode() so that
>it can be placed in docB:
>
> // the ‘true’ means to perform a deep importation (the whole subtree)
> Node node = docB.importNode(docA.getDocumentElement(), true);
> docB.getDocumentElement().appendChild(node);
>
>--
>Cameron McCormack ? http://mcc.id.au/
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: [email protected]
>For additional commands, e-mail: [email protected]
>
>
>__________ Information from ESET NOD32 Antivirus, version of virus signature
>database 3911 (20090305) __________
>
>The message was checked by ESET NOD32 Antivirus.
>
>http://www.eset.com
>
>
>
= = = = = = = = = = = = = = = = = = = =
致
礼!
杨莹
[email protected]
2009-03-09