You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ws.apache.org by Kasun Gajasinghe <ka...@gmail.com> on 2012/02/23 15:26:44 UTC

Axiom looses information when a child element is re-added to its parent using #addChild

Hi,

I've using Axiom for some work, and I've faced this issue that I think is a
bug in Axiom. The issue occurs when a given OMElement is re-added to its
parent using parentOMElement#addChild method. In that case, the said parent
loses references to all the children after the child OMElement.

To make it clear consider the sample xml doc [1]. Now, say you retrieved
the operation named "Sandesha2OperationInOnly", by xpath or any other
means. Then, you re add it to the parent <service>. After that, service
loose references to siblings after the said retrieved element (ie.
<binding> and <parameter>). I've provided a sample code for this which I've
simplified to not use xpath for better understanding. [2]

Yes, I can do a validation on whether I'm adding a child to the same
parent, but why? This should be handled at Axiom level. The example was a
much simplified version; I've spent hours wondering how I lost all those
information, and found that a seemingly innocent method invocation was the
cause! :) Can anyone reproduce this? I'd like to provide a patch for this.

[1]
<service name="HelloService">
    <operation name="Sandesha2OperationOutIn"/>
    <operation name="Sandesha2OperationInOnly"/>
    <binding name="HelloServiceSoap12Binding">
        <operation name="greet"/>
    </binding>
    <parameter name="name1">val1</parameter>
</service>

[2]
OMElement documentEle = new
StAXOMBuilder("resources/services-op-test.xml").getDocumentElement();

// Now retrieve <operation name="Sandesha2OperationInOnly" />
OMElement opElement2 = (OMElement)
documentEle.getFirstElement().getNextOMSibling().getNextOMSibling();
//OMElement opElement2 = new
AXIOMXPath("/service/operation[@name=\"Sandesha2OperationInOnly\"]").selectSingleNode(documentEle);

documentEle.addChild(opElement2);


-- 
~~~*******'''''''''''''*******~~~
*Kasun Gajasinghe*
Software Engineer; WSO2 Inc.; http://wso2.com,
*linked-in: *http://lk.linkedin.com/in/gajasinghe*
*
*blog: **http://blog.kasunbg.org* <http://blog.kasunbg.org/>

*
twitter: **http://twitter.com/kasunbg* <http://twitter.com/kasunbg>

Re: Axiom looses information when a child element is re-added to its parent using #addChild

Posted by Kasun Gajasinghe <ka...@gmail.com>.
On Tue, Feb 28, 2012 at 2:14 AM, Andreas Veithen
<an...@gmail.com>wrote:

> Should be fixed now (see AXIOM-411). Thanks for reporting this issue.
>

Great. Glad to be of help!

--Kasun


>
> Andreas
>
> On Thu, Feb 23, 2012 at 15:26, Kasun Gajasinghe <ka...@gmail.com> wrote:
> > Hi,
> >
> > I've using Axiom for some work, and I've faced this issue that I think
> is a
> > bug in Axiom. The issue occurs when a given OMElement is re-added to its
> > parent using parentOMElement#addChild method. In that case, the said
> parent
> > loses references to all the children after the child OMElement.
> >
> > To make it clear consider the sample xml doc [1]. Now, say you retrieved
> the
> > operation named "Sandesha2OperationInOnly", by xpath or any other means.
> > Then, you re add it to the parent <service>. After that, service loose
> > references to siblings after the said retrieved element (ie. <binding>
> and
> > <parameter>). I've provided a sample code for this which I've simplified
> to
> > not use xpath for better understanding. [2]
> >
> > Yes, I can do a validation on whether I'm adding a child to the same
> parent,
> > but why? This should be handled at Axiom level. The example was a much
> > simplified version; I've spent hours wondering how I lost all those
> > information, and found that a seemingly innocent method invocation was
> the
> > cause! :) Can anyone reproduce this? I'd like to provide a patch for
> this.
> >
> > [1]
> > <service name="HelloService">
> >     <operation name="Sandesha2OperationOutIn"/>
> >     <operation name="Sandesha2OperationInOnly"/>
> >     <binding name="HelloServiceSoap12Binding">
> >         <operation name="greet"/>
> >     </binding>
> >     <parameter name="name1">val1</parameter>
> > </service>
> >
> > [2]
> > OMElement documentEle = new
> > StAXOMBuilder("resources/services-op-test.xml").getDocumentElement();
> >
> > // Now retrieve <operation name="Sandesha2OperationInOnly" />
> > OMElement opElement2 = (OMElement)
> > documentEle.getFirstElement().getNextOMSibling().getNextOMSibling();
> > //OMElement opElement2 = new
> >
> AXIOMXPath("/service/operation[@name=\"Sandesha2OperationInOnly\"]").selectSingleNode(documentEle);
> >
> > documentEle.addChild(opElement2);
> >
> >
> > --
> > ~~~*******'''''''''''''*******~~~
> > Kasun Gajasinghe
> > Software Engineer; WSO2 Inc.; http://wso2.com,
> > linked-in: http://lk.linkedin.com/in/gajasinghe
> > blog: http://blog.kasunbg.org
> >
> >
> > twitter: http://twitter.com/kasunbg
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@ws.apache.org
> For additional commands, e-mail: dev-help@ws.apache.org
>
>


-- 
~~~*******'''''''''''''*******~~~
*Kasun Gajasinghe*
Software Engineer; WSO2 Inc.; http://wso2.com,
*linked-in: *http://lk.linkedin.com/in/gajasinghe*
*
*blog: **http://blog.kasunbg.org* <http://blog.kasunbg.org/>

*
twitter: **http://twitter.com/kasunbg* <http://twitter.com/kasunbg>

Re: Axiom looses information when a child element is re-added to its parent using #addChild

Posted by Andreas Veithen <an...@gmail.com>.
Should be fixed now (see AXIOM-411). Thanks for reporting this issue.

Andreas

On Thu, Feb 23, 2012 at 15:26, Kasun Gajasinghe <ka...@gmail.com> wrote:
> Hi,
>
> I've using Axiom for some work, and I've faced this issue that I think is a
> bug in Axiom. The issue occurs when a given OMElement is re-added to its
> parent using parentOMElement#addChild method. In that case, the said parent
> loses references to all the children after the child OMElement.
>
> To make it clear consider the sample xml doc [1]. Now, say you retrieved the
> operation named "Sandesha2OperationInOnly", by xpath or any other means.
> Then, you re add it to the parent <service>. After that, service loose
> references to siblings after the said retrieved element (ie. <binding> and
> <parameter>). I've provided a sample code for this which I've simplified to
> not use xpath for better understanding. [2]
>
> Yes, I can do a validation on whether I'm adding a child to the same parent,
> but why? This should be handled at Axiom level. The example was a much
> simplified version; I've spent hours wondering how I lost all those
> information, and found that a seemingly innocent method invocation was the
> cause! :) Can anyone reproduce this? I'd like to provide a patch for this.
>
> [1]
> <service name="HelloService">
>     <operation name="Sandesha2OperationOutIn"/>
>     <operation name="Sandesha2OperationInOnly"/>
>     <binding name="HelloServiceSoap12Binding">
>         <operation name="greet"/>
>     </binding>
>     <parameter name="name1">val1</parameter>
> </service>
>
> [2]
> OMElement documentEle = new
> StAXOMBuilder("resources/services-op-test.xml").getDocumentElement();
>
> // Now retrieve <operation name="Sandesha2OperationInOnly" />
> OMElement opElement2 = (OMElement)
> documentEle.getFirstElement().getNextOMSibling().getNextOMSibling();
> //OMElement opElement2 = new
> AXIOMXPath("/service/operation[@name=\"Sandesha2OperationInOnly\"]").selectSingleNode(documentEle);
>
> documentEle.addChild(opElement2);
>
>
> --
> ~~~*******'''''''''''''*******~~~
> Kasun Gajasinghe
> Software Engineer; WSO2 Inc.; http://wso2.com,
> linked-in: http://lk.linkedin.com/in/gajasinghe
> blog: http://blog.kasunbg.org
>
>
> twitter: http://twitter.com/kasunbg
>

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