On Mon, 2008-09-22 at 21:44 +0530, Saliya Ekanayake wrote:
> Hi Salu

hehe, it is Thorsten. 

The "salu2" stands for "saludos" which is Spanish for greetings. ;)

> 
> Could you please post the rootPath string, which you use to create the names
> of the elements? 

That can variate from one format to the other. However in html out put
that mostly likely will be just one 

String rootPath="/html";

> Additionally according to your XPath the "body" element
> should be the first element of the root element. 

Yes.

> So please debug and see if
> that's the first element present in your OM tree.

Yeah, it is. 

firstChild      OMElementImpl  (id=113) 
        attributes      null    
        builder null    
        done    true    
        factory OMLinkedListImplFactory  (id=80)        
        firstChild      null    
        lastChild       null    
        lineNumber      0       
        localName       "body" (id=120) 
        namespaces      null    
        nextSibling     null    
        nodeType        0       
        noPrefixNamespaceCounter        0       
        ns      null    
        parent  OMElementImpl  (id=93)  
        previousSibling null    



> 
> Just FYI, you can write much more clean code to accomplish your task. 

My ears are width open. :)

> If you
> post or explain the structure of the rootPath string I will be able to
> provide you with a much better code sample to suit your work.

The rootPath can be any string that is the common denominator for all
paths of a structurer [http://markmail.org/message/mwg5le6slrikjyak].

In html it is the root element "html" in fo it will be "fo:root". ...
but it could be basically everything like "html/body" if no injection to
"html/head" are made. The rootPath is the longest common path for all
injections.

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.

Thanks for your feedback Saliya.

salu2

> 
> Thanks,
> Saliya
> 
> On Mon, Sep 22, 2008 at 6:24 PM, Thorsten Scherler <
> [EMAIL PROTECTED]> wrote:
> 
> > Hi all,
> >
> > having following code I always get null which I do not understand:
> > OMFactory factory = OMAbstractFactory.getOMFactory();
> > StAXOMBuilder builder = new StAXOMBuilder();
> > ...
> >  String[] tokenizer = rootPath.split("/");
> >    // create all nodes that are in the root path
> >    LinkedHashSet<OMElement> path = new LinkedHashSet<OMElement>();
> >    int i = 0;
> >    for (String pathPart : tokenizer) {
> >      if (!pathPart.equals("")) {
> >        OMElement element = factory.createOMElement(pathPart, null);
> >        path.add(element);
> >      }
> >    }
> >    // now we have all nodes created but with no hierarchy
> >    OMElement[] elements = new OMElement[0];
> >    elements= path.toArray(new OMElement[path.size()]);
> >    // create the hierarchy by adding the last node to the
> >    // previous one till we reached the first one.
> >    for (int j = elements.length-1; j > 0; j--) {
> >      elements[j-1].addChild(elements[j]);
> >    }
> >    // Get rid of the overhead and expose just one node
> >    OMElement root = elements[0];
> > ...
> >     AXIOMXPath xpath = new AXIOMXPath("/html/body");
> >     OMElement injectionPoint = (OMElement)xpath.selectSingleNode(root);
> > ...
> >
> > When I debug the code I get for root:
> > root    OMElementImpl  (id=61)
> >        attributes      null
> >        builder null
> >        done    true
> >        factory OMLinkedListImplFactory  (id=50)
> >        firstChild      OMElementImpl  (id=80)
> >        lastChild       OMElementImpl  (id=80)
> >        lineNumber      0
> >        localName       "html" (id=84)
> >        namespaces      null
> >        nextSibling     null
> >        nodeType        0
> >        noPrefixNamespaceCounter        0
> >        ns      null
> >        parent  null
> >        previousSibling null
> >
> > but then for xpath.selectSingleNode(root) it always returns null.
> >
> > I am doing obvious something wrong, but I am not sure what. Is there
> > some obvious problem?
> >
> > salu2
> > --
> > Thorsten Scherler                                 thorsten.at.apache.org
> > Open Source Java                      consulting, training and solutions
> >
> >
> 
> 
-- 
Thorsten Scherler                                 thorsten.at.apache.org
Open Source Java                      consulting, training and solutions

Reply via email to