Hi Donald

Sorry for the delay getting back to you - I'm just catching up with mail
after a very long vacation.

The matches() method in dom4j used to just mean 'return true if the XPath
expression finds *anything*'. Its now changed its semantics (more on this
later). You can still use the old semantics via the selectSingleNode()
method instead.

e.g. in your code below you could use the following method instead of the
matches() call.

    if ( document.selectSingleNode( "/html/head/title" ) != null )

which amounts to the same thing you're trying to do, is there a title
element inside the head element. i.e. selectSingleNode() will return a
non-null Node if the XPath matches anything.

The matches() method now means, does the XPath expression return myself in
the result set.

So the document node isn't a title element, so

    document.matches( "/html/head/title" )

will no longer return true.

However if you did

    Node node = document.selectSingleNode( "/html/head/title" );
    node.matches( "/html/head/title" );

The above node.matches() method should always return true since it is the
<title> element, the thing at the end of the XPath.


There's a mail describing this in more detail here if it helps...

http://www.mail-archive.com/dom4j-dev%40lists.sourceforge.net/msg00315.html

James
----- Original Message -----
From: "Donald Ball" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Wednesday, April 10, 2002 10:10 PM
Subject: [dom4j-user] xpath matches method broken?


> i'm having some trouble with the Node.matches method. here is a simple
> test program that illustrates the problem:
>
> import org.dom4j.*;
>
> public class foo {
>
>         public static void main(String argv[]) throws Exception {
>                 Document document =
DocumentHelper.parseText("<html><head><title>foo</title></head><body>foobar<
/body></html>");
>                 if (document.matches("/html/head/title")) {
>                         System.out.println("matches");
>                 } else {
>                         System.out.println("doesn't match");
>                 }
>         }
>
> }
>
> the matches call returns false, even though the xpath expression
> evaluates to true (that is to say, xsl:if test on that expression
> returns true). is this a bug or a feature?
>
> - donald
>
> _______________________________________________
> dom4j-user mailing list
> [EMAIL PROTECTED]
> https://lists.sourceforge.net/lists/listinfo/dom4j-user


_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com


_______________________________________________
dom4j-user mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/dom4j-user

Reply via email to