geronimo-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From James Strachan <james_strac...@yahoo.co.uk>
Subject Re: XPath and dom4j
Date Mon, 18 Aug 2003 06:56:53 GMT
I'd also recommend the excellent XPath tutorial, takes about 20 minutes 
to do and teaches you most things you need to know about XPath...

http://www.zvon.org/xxl/XPathTutorial/General/examples.html


On Sunday, August 17, 2003, at 11:30  pm, Jan Bartel wrote:

> Chris,
>
>> I'm trying to grab a particular list of nodes using
>> dom4j from an xml document. Some things seem to work
>> and some obvious things don't. My first experience
>> with it is here..so it could be my lack of
>> understanding XPath.
>> I tried to get elements using this:
>> /ejb-jar/enterprise-beans
>> I'm expecting to get all of the child nodes directly
>> beneath /ejb-jar/enterprise-beans this way.
> You should get a list of all enterprise-bean nodes with this 
> expression (note, should be just one of these in an ejb-jar 
> descriptor), not their children."/ejb-jar/enterprise-beans/*" should 
> get you all the children.
>
>
>> I am also trying to get a single attribute of a single
>> element using this: /ejb-jar[@version]
> Well, this xpath expression would return you the attribute "version" 
> of the "ejb-jar" element at the root of the document (that is, if 
> ejb-jar had such an attribute).
>
>> The only paths that seem to work are these: "//" or
>> "@version"
>> this is the code...
>> XPath xpathSelector = DocumentHelper.createXPath(str);
>> List nodes =
>> xpathSelector.selectNodes(node.getDocument());
> It might be easier to play around with the non-compiled XPath 
> expressions until you get it sorted out, eg:
>        List nodes = document.selectNodes ("/ejb-jar/enterprise-beans");
>        nodes = document.selectNodes ("/ejb-jar/enterprise-beans/*");
>
>
>
> cheers,
> Jan
>
>

James
-------
http://radio.weblogs.com/0112098/


Mime
View raw message