Re: Importing nodes

Thomas DeWeese <[email protected]>
Newsgroups gmane.text.xml.batik.user
Message-ID <CACTtnu096WSvzzQShVx1B2ZEFUBKpkKQETWmtrsF1GrM-JDZuw@mail.gmail.com>
Sorry send got pressed early.

On Tue, Aug 14, 2012 at 8:50 AM, Thomas DeWeese <[email protected]>wrote:

> This will work but will be roughly O(N^2) rather than O(N) because the
> native data structure for DOM is a linked list of children.
> So it is _much_ better to use something like:
>
> Element newParent = doc1.getElementById("group1")
> Node current = doc2Elements.getFirstChild();
> while (current != NULL) {
>    Node copyNode = doc1.importNode(current, true);
>    newParent.appendChild(copyNode);
>    current = current.getNextSibling();
> }
>
> On Mon, Aug 13, 2012 at 5:56 PM, jonathan wood <[email protected]
> > wrote:
>
>> for (int el = 0; el < numberOfNewElements; el++) {
>>     Node anElement = doc2Elements.item(el);
>>     Node copyNode = doc1.importNode(anElement, true);
>>  //   doc1Root.appendChild(copyNode);
>>     doc1.getElementById("group1").appendChild(copyNode);
>>
>> }
>>
>> On Mon, Aug 13, 2012 at 3:29 PM, fireball <[email protected]> wrote:
>>
>>> Let's say I have two documents:
>>>
>>> document 1:
>>> <svg
>>>   <g id="group1"
>>>      ...
>>>   </g>
>>> </svg>
>>>
>>> and
>>>
>>> document 2:
>>> <svg
>>>   <g id="group2"
>>>      ...
>>>   </g>
>>> </svg>
>>>
>>> If I want to import doc 2 into doc 1 I do something like this:
>>>
>>> Element doc1Root = doc1.getDocumentElement();
>>> Element doc2Root = doc2.getDocumentElement();
>>>
>>> NodeList doc2Elements = doc2Root.getChildNodes();
>>> int numberOfNewElements = doc2Elements.getLength();
>>> for (int el = 0; el < numberOfNewElements; el++) {
>>>     Node anElement = doc2Elements.item(el);
>>>     Node copyNode = doc1.importNode(anElement, true);
>>>     doc1Root.appendChild(copyNode);
>>> }
>>>
>>>
>>> This results in two groups within doc1:
>>> <svg
>>>   <g id="group1"
>>>      ...
>>>   </g>
>>>   <g id="group2"
>>>      ...
>>>   </g>
>>> </svg>
>>>
>>> Now my question is, how do we import this doc2 into group1 of doc1. I.e.
>>> something like:
>>> <svg
>>>   <g id="group1"
>>>      ...
>>>      <g id="group2"
>>>      ...
>>>      </g>
>>>   </g>
>>> </svg>
>>>
>>>
>>>
>>> --
>>> View this message in context:
>>> http://batik.2283329.n4.nabble.com/Importing-nodes-tp4655201.html
>>> Sent from the Batik - Users mailing list archive at Nabble.com.
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: [email protected]
>>> For additional commands, e-mail: [email protected]
>>>
>>>
>>
>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.