In http://www.mail-archive.com/dom4j-user%40lists.sourceforge.net/msg00088.html
James wrote:

  AFAIK when you don't put prefixes in an XPath expression it should just
  match on local name only (i.e. ignores prefixes)

Did that turn out not to be the case? In the appended example the first
test returns 0. Am I doing somthing wrong?

-- Martijn

import java.io.*;
import java.util.*;
import org.dom4j.*;
import org.dom4j.io.*;

public class sss
{
    public static void main(String argv[])
    {
        try {                
            process();
        }
        catch(Exception e) {
            e.printStackTrace(System.err);
        }
    }

    public static void process()
        throws Exception {
        
        String NS = "http://www.example.org/my";;

        Document document = DocumentHelper.createDocument();
        Element root = document.addElement( "root" );
        root.addNamespace("my", NS);
        Element aaa = root.addElement( "my:aaa", NS );

        OutputFormat format = OutputFormat.createCompactFormat();
        XMLWriter writer = new XMLWriter( System.out, format );
        writer.write( document );
        System.out.println();

        test(document, "//aaa");
        test(document, "//my:aaa");
        test(document, "//*:aaa");
    }

    public static void test(Document document, String xpathExpression) {
        List nodes = document.selectNodes(xpathExpression);
        System.out.println(xpathExpression + ": " +
           (nodes == null ? -1 : nodes.size()));
    }
}

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

Reply via email to