On Wed, 2002-04-10 at 17:10, Donald Ball wrote:
> 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?
no luck here, huh? would this be appropriate on the jaxen list? fwiw, i
have managed a workaround by doing this:
/**
FIXME - why doesn't this work?
if (!document.matches(xpath)) {
**/
Object object =
document.selectObject(xpath);
boolean matches = false;
if (object != null) {
if (object instanceof String) {
matches = true;
} else if (object instanceof
Number) {
matches = true;
} else if (object instanceof
Node) {
matches = true;
} else if (object instanceof
Boolean) {
matches = true;
} else if (object instanceof
List) {
List list =
(List)object;
if (!list.isEmpty()) {
matches = true;
}
} else {
throw new
IllegalStateException("Invalid object type returned from selectObject:
"+object.getClass().getName());
}
_______________________________________________
dom4j-user mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/dom4j-user