Hi Dave
 
The XPath expression /slideshow/@title will return an Attribute object. Using the [] notation evaluates a predicate on the current node. So if you wanted to find the 'title' attributes for all the slideshow's that have a colour="blue" attribute you could use
 
/slideshow[@colour='blue']/@title
 
If all you want is the value of the title attribute then
 
    String value = doc.valueOf( "/slideshow/@title" );
 
should do fine.
 
If you need some help understanding XPath the links on the http://dom4j.org site might help - Check out the 'Useful links' section with Elliotte's article and the Zvon tutorial - both are excellent introductions to XPath.

James
----- Original Message -----
Sent: Wednesday, February 13, 2002 7:12 PM
Subject: [dom4j-user] xpath selectSingleNode to get an attribute

Hi;

If I call:
    Node node = doc.selectSingleNode( "/slideshow[@title]" );

It does not return the attribute for title - it returns the slideshow element. I then have to do node.valueOf to get the attribute. It seems logical to me that if I request an attribute in my xpath command, that I should get the attribute back as the node.
 
And if I can't do that, is there any easy way to select the attribute part of an xpath request out? I get these strings from users so I have to parse it out in this case.

????? - thanks - dave

Reply via email to