synapse-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Saliya Ekanayake <esal...@gmail.com>
Subject Re: XPath evaluation doesn't work on resources picked from registry
Date Sat, 20 Jun 2009 16:10:33 GMT
Hi,

Um, I am not really clarified with the problem here. I agree that the full
tree should be built before we can evaluate XPath. Adding the element to a
new OMDocument, however, just to get this done seems not right.
Additionally, the original OMDocument created by the builder will be there
even if you detach the element. Detach will only remove the element from the
tree to which it belongs. To check this, you can get the builder from the
detached element and ask for the OMDocument.  IMHO, we can call
result.build() if necessary.

Btw. I am not clear why XPath doesn't work on the detached element. I did a
simple test as follows and XPath worked, may be I have missed something
(please let me know if so).

    public static void main(String[] args) throws XMLStreamException,
JaxenException {
        String str = "<hello><something>wow
nice</something><anotherthing><insideanother>great</insideanother></anotherthing></hello>";
        StAXOMBuilder builder = new StAXOMBuilder(new
ByteArrayInputStream(str.getBytes()));
        OMElement root = builder.getDocumentElement();

        OMDocument doc = builder.getDocument();
        System.out.println(doc == null);

        OMElement anotherthing = root.getFirstChildWithName(new
QName("anotherthing"));
        anotherthing.detach();

        doc = ((StAXOMBuilder)anotherthing.getBuilder()).getDocument();
        System.out.println(doc == null);

        AXIOMXPath xpath = new AXIOMXPath("//insideanother");
        OMElement node = (OMElement) xpath.selectSingleNode(anotherthing);
        System.out.println(node.getText());
    }

Thanks,
Saliya

On Sat, Jun 20, 2009 at 4:45 AM, Andreas Veithen
<andreas.veithen@gmail.com>wrote:

> StAXOMBuilder actually already creates an OMDocument (which can be
> retrieved by the getDocument method). The important thing is that we
> need to make sure that the Axiom tree is fully built before closing
> the input stream. I guess that the detach method is used because it
> has the side effect of fully building the element and because
> OMDocument has no method to build the entire tree (see WSCOMMONS-479).
>
> This gives us two solutions:
>
> - Use StAXOMBuilder#getDocument and iterate over its children to make
> sure the document is fully built.
> - Continue to use "detach" and add the element to a new document, as
> you suggested. Note that you should not use OMDocumentImpl directly,
> but create it using the OMFactory.
>
> Andreas
>
> On Fri, Jun 19, 2009 at 09:30, indika kumara<indika.kuma@gmail.com> wrote:
> > Devs
> >
> > $subject is due to we do  'detach()'  on picked resource OMElement .
> > If I add detached element to a OMDocument as a child, it works
> >
> > Existing code  SImpleURLRegistry
> >
> > result.detach();
> > inputStream.close();
> >
> >
> > Modified code
> >
> > result.detach();
> > OMDocumentImpl omDocument = new OMDocumentImpl();
> > omDocument.addChild(result);
> > inputStream.close();
> >
> >
> > Are there any best solution other than what I did ?  I haven't deep
> > AXIOM knowledge?  Could anyone help me?
> >
> > Thanks
> > Indika
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: dev-unsubscribe@synapse.apache.org
> > For additional commands, e-mail: dev-help@synapse.apache.org
> >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@synapse.apache.org
> For additional commands, e-mail: dev-help@synapse.apache.org
>
>


-- 
Saliya Ekanayake
http://www.esaliya.blogspot.com
http://www.esaliya.wordpress.com

Mime
View raw message