Hi Piero

> - Node.getUniquePath() does not give me a unique path>
> If I have this xml:
>
> <root>
>   <section>
>        <page></page>
>   </section>
>   <section>
>     <page>i am here</page>
> </root>
>
> and my node is pointing to the second <page> tag,
>  and I do getUniquePath(), instead of getting
> /root/section[2]/page ,
> I get
> /root/section/page

Which version of dom4j are you using?

I've added your scenario to the JUnit test harness locally (I'll check it in
on Mondy) and it appears to work fine against 0.6 of dom4j.


> So I cannot navigate back to where I was using that
> XPath string ( I would go to the first <page> )
> maybe I don't understand Xpath?

You could always keep a reference to the page Element around?

But you're right, the getUniquePath() should be returning
/root/section[2]/page .


> - how do I switch back and forth between Node and
> Element? Say I do Node n =
> Document.SelectSingleNode("XPath exp.."). How do I
> make it into an Element ? And the other way around ?
> Is Branch involved in any way?

Branch extends Node
Element extends Branch

So Element is-a Node. So you can cast from a Node to an Element

    Element element = (Element) document.selectSingleNode(
"/root/section[2]/page" );

You can go back the other way without a cast.

    Node node = element;.

James


_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com


_______________________________________________
dom4j-user mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/dom4j-user

Reply via email to