[ 
https://issues.apache.org/jira/browse/WSCOMMONS-388?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12634104#action_12634104
 ] 

Saliya Ekanayake commented on WSCOMMONS-388:
--------------------------------------------

The reason for the issue is as follows.

According to XPath syntax the symbol "/" resolves to the document root context 
[1]. In the case of building an OM tree from a stream an OMDocument is created 
and the elements are added to it. Therefore the XPath "/html/body" resolves to 
an "body" element inside "html" element which of course is in the document root 
(i.e. inside the OMDocument).

In the case of creating an OM tree directly we don't provide an OMDocument. 
Therefore the "/" context resolves to the root element as it's the document 
root. In this case the XPath "/html/body" is null as there is no "html" element 
inside the document root context ("html" is in fact the document root).

The issue comes because Axiom does not enforce creating an OMDocument when 
representing an XML infoset.  The simple solution that you can do is to add the 
following two lines to your code.

OMDocument doc = factory.createOMDocument();
doc.addChild(root);

Therefore I think this is not an issue with Axiom. Please correct me if I am 
wrong here.

Regards,
Saliya

> Creating a model directly from a factory and not a builder AXIOMXPath will 
> always return you null.
> --------------------------------------------------------------------------------------------------
>
>                 Key: WSCOMMONS-388
>                 URL: https://issues.apache.org/jira/browse/WSCOMMONS-388
>             Project: WS-Commons
>          Issue Type: Bug
>          Components: AXIOM
>            Reporter: Thorsten Scherler
>
> On Tue, Sep 23, 2008 at 4:14 PM, Thorsten Scherler <
> > On Tue, 2008-09-23 at 11:53 +0200, Thorsten Scherler wrote:
> > > I wonder - reading your other answers - whether AXIOMXPath is only
> > > working with OM's that a builder has generated (parsing a file) and
> > > not
> > > like I do an OMElement that I created from the factory (without
> > > parsing
> > > a file), hence builder = null.
> >
> > I did a small test where I created a file and used it instead the former
> > approach to create the OMElement via the factory and this revealed that
> > above suspicion is right. The objects are identically besides the
> > builder which seems to make all the difference.
> >
> > If you create a model directly from a factory and not a builder
> > AXIOMXPath will not return you any node.
> Code to reproduce:
> OMElement root = factory.createOMElement("root", null);
> OMElement child = factory.createOMElement("child", null);
> root.addChild(child);
> AXIOMXPath xpath = new AXIOMXPath("/root/child");
> OMElement injectionPoint = (OMElement)xpath.selectSingleNode(root);
> if(null==injectionPoint){
>  System.out.println("Should not be null, but the child node");
> }

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to