On Tue, 6 Nov 2001, George Pieri wrote:

> I am looking for a small example of what I need to do use
> Jaxen and XPath with JDOM. I am already familar with JDom and
> would just like to know what Jaxen classes I should instantiate
> for it to evaluate an XPATH expression that will go against my
> JDOM tree

Unpack the distribution, and look in this directory:

        jaxen-1.0-beta-7/src/java/samples/

Should exist a file called JDOMDemo.java, showing you exactly
what you want.  (I really need to put this in a FAQ.  Lots of
folks have asked.  Doesn't anyone browse source anymore?)

>        XPathElement xpath = new XPathElement("/customer/invoice=1111");
>        org.jdom.Element = xpath.getTextMatch(root,expr);

First, no class named XPathElement.  Where are you digging that
up?  It might be helpful to read the JavaDocs for the API, located
in this directory:

        jaxen-1.0-beta-7/doc/javadoc/

Plus...  The expr of "/customer/invoice=1111" will offer up a
boolean result, not an Element.  You probably want something
more along the lines of:

        /customer/invoice[.=1111]

That selects <invoice> children of a <customer> root element,
where the value of the text within the <invoice> element is
equal to 1111.  You'll get back a List if you use selectNodes()
or the first matching element if you use selectSingleNode().

Jaxen's XPath object takes an xpath-expression, not just a
predicate.  As such, you can even just do arithmetic with
jaxen, if you like, using valid xpath exprs like "$foo + 8".

        -bob


_______________________________________________
Jaxen-interest mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jaxen-interest

Reply via email to