in reply to HTML and Xpath
//div[@class="here"]
is short for
/descendant::div[@class="here"]
The leading "/" means the root. Since you want a relative path rather than an absolute path, what you want is
descendant::div[@class="here"]
In this case,
child::div[@class="here"]
would also do, and that can be abbreviated to
div[@class="here"]
detach and clone work because the detached/cloned element becomes the root of the detached/cloned tree. In that situation, there is no difference between a relative path an an absolute path. However, they are needlessly expensive, they prevent you from looking at the node's ancestors (since you removed them) and detach destroys the tree. I wouldn't use either of those solution.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: HTML and Xpath
by way (Sexton) on Nov 15, 2008 at 20:12 UTC |