You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xalan.apache.org by Jeong Ahn Lee <je...@yahoo.com> on 2002/06/19 12:44:04 UTC

How to insert an element?

Hi all, i have an xml document like below

<SOAP-ENV:Envelope>
	<SOAP-ENV:Header>
		<ABC>aa</ABC>
		<BBC>bb</BBC>
		<CNN>bb</CNN>
	</SOAP-ENV:Header>
	<SOAP-ENV:Body>this is body</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

in that document, how can i insert an element( say
<FOX> )
after <CNN> element, with in the <SOAP-ENV:Header>
element.
if it was before <CNN> i could have used 

public Node insertBefore(Node newChild,
                         Node refChild)
                  throws DOMException

this method which is there org.w3c.dom.Node interface,
there is no method called insertAfter(...), so i want
to know is there any workaround for that.

regards

__________________________________________________
Do You Yahoo!?
Yahoo! - Official partner of 2002 FIFA World Cup
http://fifaworldcup.yahoo.com

Re: How to insert an element?

Posted by Avnish Pundir <ap...@cisco.com>.
Hi Jeong,
Use the node you want to append after
Node mynode = doc.getElementsByTagName("CNN").item(0);

Get it's immediate next node
Node nextNode = mynode.getNextSibling();

Append your new node just before this
if (nextNode != null) {
    doc.insertBefore(myNewNode,nextNode);
} else {
    // This will append new Node right at end of child list.
    doc.appendChild(myNewNode);
}

Hope this helps.

Thanks
Avnish
----- Original Message -----
From: "Jeong Ahn Lee" <je...@yahoo.com>
To: <xa...@xml.apache.org>; <xa...@xml.apache.org>;
<xe...@xml.apache.org>
Sent: Wednesday, June 19, 2002 4:14 PM
Subject: How to insert an element?


Hi all, i have an xml document like below

<SOAP-ENV:Envelope>
<SOAP-ENV:Header>
<ABC>aa</ABC>
<BBC>bb</BBC>
<CNN>bb</CNN>
</SOAP-ENV:Header>
<SOAP-ENV:Body>this is body</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

in that document, how can i insert an element( say
<FOX> )
after <CNN> element, with in the <SOAP-ENV:Header>
element.
if it was before <CNN> i could have used

public Node insertBefore(Node newChild,
                         Node refChild)
                  throws DOMException

this method which is there org.w3c.dom.Node interface,
there is no method called insertAfter(...), so i want
to know is there any workaround for that.

regards

__________________________________________________
Do You Yahoo!?
Yahoo! - Official partner of 2002 FIFA World Cup
http://fifaworldcup.yahoo.com



Re: How to insert an element?

Posted by Avnish Pundir <ap...@cisco.com>.
Hi Jeong,
Use the node you want to append after
Node mynode = doc.getElementsByTagName("CNN").item(0);

Get it's immediate next node
Node nextNode = mynode.getNextSibling();

Append your new node just before this
if (nextNode != null) {
    doc.insertBefore(myNewNode,nextNode);
} else {
    // This will append new Node right at end of child list.
    doc.appendChild(myNewNode);
}

Hope this helps.

Thanks
Avnish
----- Original Message -----
From: "Jeong Ahn Lee" <je...@yahoo.com>
To: <xa...@xml.apache.org>; <xa...@xml.apache.org>;
<xe...@xml.apache.org>
Sent: Wednesday, June 19, 2002 4:14 PM
Subject: How to insert an element?


Hi all, i have an xml document like below

<SOAP-ENV:Envelope>
<SOAP-ENV:Header>
<ABC>aa</ABC>
<BBC>bb</BBC>
<CNN>bb</CNN>
</SOAP-ENV:Header>
<SOAP-ENV:Body>this is body</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

in that document, how can i insert an element( say
<FOX> )
after <CNN> element, with in the <SOAP-ENV:Header>
element.
if it was before <CNN> i could have used

public Node insertBefore(Node newChild,
                         Node refChild)
                  throws DOMException

this method which is there org.w3c.dom.Node interface,
there is no method called insertAfter(...), so i want
to know is there any workaround for that.

regards

__________________________________________________
Do You Yahoo!?
Yahoo! - Official partner of 2002 FIFA World Cup
http://fifaworldcup.yahoo.com



---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-dev-help@xml.apache.org


Re: How to insert an element?

Posted by Jeong Ahn Lee <je...@yahoo.com>.
thank you all,

i found out a way( work around) for that.

regards


--- Jeong Ahn Lee <je...@yahoo.com> wrote:
> Hi all, i have an xml document like below
> 
> <SOAP-ENV:Envelope>
> 	<SOAP-ENV:Header>
> 		<ABC>aa</ABC>
> 		<BBC>bb</BBC>
> 		<CNN>bb</CNN>
> 	</SOAP-ENV:Header>
> 	<SOAP-ENV:Body>this is body</SOAP-ENV:Body>
> </SOAP-ENV:Envelope>
> 
> in that document, how can i insert an element( say
> <FOX> )
> after <CNN> element, with in the <SOAP-ENV:Header>
> element.
> if it was before <CNN> i could have used 
> 
> public Node insertBefore(Node newChild,
>                          Node refChild)
>                   throws DOMException
> 
> this method which is there org.w3c.dom.Node
> interface,
> there is no method called insertAfter(...), so i
> want
> to know is there any workaround for that.
> 
> regards
> 
> __________________________________________________
> Do You Yahoo!?
> Yahoo! - Official partner of 2002 FIFA World Cup
> http://fifaworldcup.yahoo.com


__________________________________________________
Do You Yahoo!?
Yahoo! - Official partner of 2002 FIFA World Cup
http://fifaworldcup.yahoo.com

---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org


Re: How to insert an element?

Posted by Jeong Ahn Lee <je...@yahoo.com>.
thank you all,

i found out a way( work around) for that.

regards


--- Jeong Ahn Lee <je...@yahoo.com> wrote:
> Hi all, i have an xml document like below
> 
> <SOAP-ENV:Envelope>
> 	<SOAP-ENV:Header>
> 		<ABC>aa</ABC>
> 		<BBC>bb</BBC>
> 		<CNN>bb</CNN>
> 	</SOAP-ENV:Header>
> 	<SOAP-ENV:Body>this is body</SOAP-ENV:Body>
> </SOAP-ENV:Envelope>
> 
> in that document, how can i insert an element( say
> <FOX> )
> after <CNN> element, with in the <SOAP-ENV:Header>
> element.
> if it was before <CNN> i could have used 
> 
> public Node insertBefore(Node newChild,
>                          Node refChild)
>                   throws DOMException
> 
> this method which is there org.w3c.dom.Node
> interface,
> there is no method called insertAfter(...), so i
> want
> to know is there any workaround for that.
> 
> regards
> 
> __________________________________________________
> Do You Yahoo!?
> Yahoo! - Official partner of 2002 FIFA World Cup
> http://fifaworldcup.yahoo.com


__________________________________________________
Do You Yahoo!?
Yahoo! - Official partner of 2002 FIFA World Cup
http://fifaworldcup.yahoo.com

Re: How to insert an element?

Posted by Jeong Ahn Lee <je...@yahoo.com>.
thank you all,

i found out a way( work around) for that.

regards


--- Jeong Ahn Lee <je...@yahoo.com> wrote:
> Hi all, i have an xml document like below
> 
> <SOAP-ENV:Envelope>
> 	<SOAP-ENV:Header>
> 		<ABC>aa</ABC>
> 		<BBC>bb</BBC>
> 		<CNN>bb</CNN>
> 	</SOAP-ENV:Header>
> 	<SOAP-ENV:Body>this is body</SOAP-ENV:Body>
> </SOAP-ENV:Envelope>
> 
> in that document, how can i insert an element( say
> <FOX> )
> after <CNN> element, with in the <SOAP-ENV:Header>
> element.
> if it was before <CNN> i could have used 
> 
> public Node insertBefore(Node newChild,
>                          Node refChild)
>                   throws DOMException
> 
> this method which is there org.w3c.dom.Node
> interface,
> there is no method called insertAfter(...), so i
> want
> to know is there any workaround for that.
> 
> regards
> 
> __________________________________________________
> Do You Yahoo!?
> Yahoo! - Official partner of 2002 FIFA World Cup
> http://fifaworldcup.yahoo.com


__________________________________________________
Do You Yahoo!?
Yahoo! - Official partner of 2002 FIFA World Cup
http://fifaworldcup.yahoo.com

---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-dev-help@xml.apache.org


Re: How to insert an element?

Posted by Jeong Ahn Lee <je...@yahoo.com>.
thank you all,

i found out a way( work around) for that.

regards


--- Jeong Ahn Lee <je...@yahoo.com> wrote:
> Hi all, i have an xml document like below
> 
> <SOAP-ENV:Envelope>
> 	<SOAP-ENV:Header>
> 		<ABC>aa</ABC>
> 		<BBC>bb</BBC>
> 		<CNN>bb</CNN>
> 	</SOAP-ENV:Header>
> 	<SOAP-ENV:Body>this is body</SOAP-ENV:Body>
> </SOAP-ENV:Envelope>
> 
> in that document, how can i insert an element( say
> <FOX> )
> after <CNN> element, with in the <SOAP-ENV:Header>
> element.
> if it was before <CNN> i could have used 
> 
> public Node insertBefore(Node newChild,
>                          Node refChild)
>                   throws DOMException
> 
> this method which is there org.w3c.dom.Node
> interface,
> there is no method called insertAfter(...), so i
> want
> to know is there any workaround for that.
> 
> regards
> 
> __________________________________________________
> Do You Yahoo!?
> Yahoo! - Official partner of 2002 FIFA World Cup
> http://fifaworldcup.yahoo.com


__________________________________________________
Do You Yahoo!?
Yahoo! - Official partner of 2002 FIFA World Cup
http://fifaworldcup.yahoo.com