Hi Salu
Could you please post the rootPath string, which you use to create the names
of the elements? Additionally according to your XPath the "body" element
should be the first element of the root element. So please debug and see if
that's the first element present in your OM tree.
Just FYI, you can write much more clean code to accomplish your task. 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.
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
>
>
--
Saliya Ekanayake
http://www.esaliya.blogspot.com
http://www.esaliya.wordpress.com