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 emzic <em...@embege.com> on 2008/07/22 11:09:52 UTC

how to append an element after another element on same depth

hello,

this is more a DOM-question than a batik question.

how can i attach a node (basically a <g>) right after another node (maybe a
g, path, rect, circle, ...).
it should be the next sibling then, so that as an svg it shows up above it.


i tried it with

element.getNextSibling().getNextSibling().appendChild(importedElement);

the first sibling is the text-node and the next seems to be the
closing-node. so appending right after that should do the trick.

sometimes this works, but sometimes it results in NPE, since the element
does not always seem to have two siblings.

thanks for any help on this!
-- 
View this message in context: http://www.nabble.com/how-to-append-an-element-after-another-element-on-same-depth-tp18585283p18585283.html
Sent from the Batik - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org


Re: how to append an element after another element on same depth

Posted by Luca Piccarreta <lu...@gmail.com>.
The code looks correct to me,
are you sure that importedNode comes really from the same
document of element? (check that getOwnerDocument() is the
same)
To be honest, I don't remember if insertBefore accepts a null
as the first argument to the call (the case in which element has
no nextSibling), this might generate errors.
Another corner case could be that element and importedNode are
the same Java Object...
Anyone on the list can shed light?
Luca.

On Tue, Jul 22, 2008 at 11:58 AM, emzic <em...@embege.com> wrote:

>
>
> Luca Piccarreta wrote:
> >
> > Hi emzic,
> > What you want to do is, probably:
> >
> >      Node parentNode = element.getParentNode();
> >      parentNode.insertBefore(element.getNextSibling(),importedNode)
> >
>
> thank you very much for your answer, Luca.
>
> unfortunately that gives me this dom exception:
>
> org.w3c.dom.DOMException: The child node (type: 1, name: g) is missing.
>        at org.apache.batik.dom.AbstractNode.createDOMException(Unknown
> Source)
>        at org.apache.batik.dom.AbstractParentNode.insertBefore(Unknown
> Source)
> --
> View this message in context:
> http://www.nabble.com/how-to-append-an-element-after-another-element-on-same-depth-tp18585283p18586026.html
> Sent from the Batik - Users mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
> For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org
>
>

Re: how to append an element after another element on same depth

Posted by emzic <em...@embege.com>.

thomas.deweese wrote:
> 
>      Node parentNode = element.getParentNode();
>      parentNode.insertBefore(importedNode, element.getNextSibling());
> 

hooray, this works! thank you very much!
-- 
View this message in context: http://www.nabble.com/how-to-append-an-element-after-another-element-on-same-depth-tp18585283p18586327.html
Sent from the Batik - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org


Re: how to append an element after another element on same depth

Posted by th...@kodak.com.
Hi Emzic,

emzic <em...@embege.com> wrote on 07/22/2008 05:58:15 AM:

> Luca Piccarreta wrote:

> >      Node parentNode = element.getParentNode();
> >      parentNode.insertBefore(element.getNextSibling(),importedNode)
> > 
> 
> thank you very much for your answer, Luca.
> 
> unfortunately that gives me this dom exception:
> 
> org.w3c.dom.DOMException: The child node (type: 1, name: g) is missing.

   Luca, needs to check the docs (like I need to do every time ;), 
'importedNode' and 'element.getNextSibling()' are in the wrong order.
The code should be:

     Node parentNode = element.getParentNode();
     parentNode.insertBefore(importedNode, element.getNextSibling());

Re: how to append an element after another element on same depth

Posted by emzic <em...@embege.com>.

Luca Piccarreta wrote:
> 
> Hi emzic,
> What you want to do is, probably:
> 
>      Node parentNode = element.getParentNode();
>      parentNode.insertBefore(element.getNextSibling(),importedNode)
> 

thank you very much for your answer, Luca.

unfortunately that gives me this dom exception:

org.w3c.dom.DOMException: The child node (type: 1, name: g) is missing.
	at org.apache.batik.dom.AbstractNode.createDOMException(Unknown Source)
	at org.apache.batik.dom.AbstractParentNode.insertBefore(Unknown Source)
-- 
View this message in context: http://www.nabble.com/how-to-append-an-element-after-another-element-on-same-depth-tp18585283p18586026.html
Sent from the Batik - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org


Re: how to append an element after another element on same depth

Posted by Luca Piccarreta <lu...@gmail.com>.
Hi emzic,
What you want to do is, probably:

     Node parentNode = element.getParentNode();
     parentNode.insertBefore(element.getNextSibling(),importedNode)

Cheers,
Luca.

emzic wrote:
> hello,
>
> this is more a DOM-question than a batik question.
>
> how can i attach a node (basically a<g>) right after another node (maybe a
> g, path, rect, circle, ...).
> it should be the next sibling then, so that as an svg it shows up above it.
>
>
> i tried it with
>
> element.getNextSibling().getNextSibling().appendChild(importedElement);
>
> the first sibling is the text-node and the next seems to be the
> closing-node. so appending right after that should do the trick.
>
> sometimes this works, but sometimes it results in NPE, since the element
> does not always seem to have two siblings.
>
> thanks for any help on this!
>    


---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org