[jdom-interest] XPath?

Frank Sauer Frank.Sauer at trcinc.com
Wed Sep 19 12:35:50 PDT 2001


I get the same results with werken.xpath as well as jaxen
and I just downloaded the contrib stuff from the CVS 
repository, which according to the README is an 'old'
version of werken.xpath. Again, same result, which is
an empty String on the "name/text()" expression, when
evaluated as follows:

        private String eval(Element context, String expr) {
            String result = null;
            try {
                XPathElement xpath = new XPathElement(context);
                result = xpath.getTextMatch(expr);
            } catch (Exception x) {
                x.printStackTrace();
            }
            return result;
        }

Here, the context element is the <tag> element, and expr
is "name/text()". The result is an empty String, but it
should not be... The above code is from Jason's xpath sample,
the only difference is that the context element is not the
root element of the Document. I'm trying to use XPath expressions
to customize the look of a JTree rendering an XML document.

Thanks,

Frank Sauer
The Technical Resource Connection, Inc.
a wholly owned subsidiary of Perot Systems
Tampa, FL
http://www.trcinc.com
-----------------------------------------------
Java: The best argument for Smalltalk since C++


-----Original Message-----
From: bob mcwhirter [mailto:bob at werken.com]
Sent: Wednesday, September 19, 2001 3:14 PM
To: Frank Sauer
Cc: jdom-interest at jdom.org
Subject: Re: [jdom-interest] XPath?


On Wed, 19 Sep 2001, Frank Sauer wrote:

> I'm trying to use an XPath engine with JDOM to obtain the textual
> content of the <name> element under the <tag> element in a taglib tld
> file. I tried to use both werken.xpath and jaxen, but can't
> get either to work. The context node is the <tag> element, so I tried
> all of the following expressions:
> 
> name

	This should select the <name> org.jdom.Element

> name/text()

	This *should* select the string-value of the org.jdom.Element,
	which recursively constructs the string based upon sub-elements
	too.

> child::name

	This is the same as 'name' above.

> child::name/text()

	This is the same as 'name/text()' above.

> /name

	This will only select the root element if its
	a <name> tag, else an empty-set will be returned.

> //name

	This will select all <name> elements within your
	document.

My question now:

*Which* XPath engine are you using?

	-bob



More information about the jdom-interest mailing list