Hi Eddie Thanks for that. I guess thats my question; should the 'root' be the context node on which the XPath expression evaluates or should 'root' always be the document? (Lets not worry about document fragments for this discussion)
I always thought it should be the document, otherwise the use of "/" at the start of an expression adds no extra value. Lets take an example. <foo c="123"> <bar> <x> <y>hello</y> </x> </bar> </foo> Lets say we get access to the <bar> element. (Using dom4j code for a second). Node bar = document.selectSingleNode( "/foo/bar" ); Now typically if I wanted to navigate relative to the <bar> element I'd just use a relative XPath expression which does not start with "/". Node y = bar.selectSingleNode( "x/y" ); There's no need for me to start the expression with "/" since the XPath expression will start from <bar> anyway as its relative. However if I wanted to get access to the c attribute, I could do Node c = bar.selectSingleNode( "/@c" ); Couldn't I? i.e. the addition of "/" to the front of the XPath expression means use the document as the root, not the node I happen to be evaluating the expression on, which is <bar>. If the "/" means use the evaluation context as the root then there is no difference between "/@c" and "@c" which would seem pretty pointless to me. Is my understanding correct here? There does seem to be a bit of confusion on this topic. James ----- Original Message ----- From: "Eddie" <[EMAIL PROTECTED]> To: "James Strachan" <[EMAIL PROTECTED]> Sent: Tuesday, November 20, 2001 10:02 AM Subject: Re: [Jaxen] Paths beginning with / should start from document? > James, > if an XPath starts with a "/" then it is an absolute path and is taken as > meaning the root node. The "root" is usually the Document node but doesn't > necessarily need to be. It could be just the root of a particular branch. > The root is defined by the context that you set before evaluation using the > method Context.setNodeSet(List nodeSet). I'm not sure what is supposed to > happen if you have no root but several top level nodes. You probably get an > exception or an empty result set. > Hope this helps > Eddie > > > ----- Original Message ----- > From: "James Strachan" <[EMAIL PROTECTED]> > To: "Jaxen-Interest" <[EMAIL PROTECTED]> > Sent: Tuesday, November 20, 2001 9:26 AM > Subject: [Jaxen] Paths beginning with / should start from document? > > > > Just a quick clarifcation that I wanted to double check with the list. Any > > XPath expression that starts with "/" should always start from the > document > > of the node on which the XPath is evaluated, shouldn't it? > > > > i.e. the behaviour is like a file system where whatever directory (node) > you > > evaluate a path expression, anything starting with "/" starts from the > root > > directory (the document). > > > > This is true isn't it? > > > > James > > > > > > _________________________________________________________ > > Do You Yahoo!? > > Get your free @yahoo.com address at http://mail.yahoo.com > > > > > > _______________________________________________ > > Jaxen-interest mailing list > > [EMAIL PROTECTED] > > https://lists.sourceforge.net/lists/listinfo/jaxen-interest _________________________________________________________ Do You Yahoo!? Get your free @yahoo.com address at http://mail.yahoo.com _______________________________________________ Jaxen-interest mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/jaxen-interest