jdom中目前只有XPath的interface,没有XPath的implementation
apache的xalan-j中有XPath的implementation,但你需要由jdom转向以sun的JAXP为基础的apache xerces-j和xalan-j

解决方案 »

  1.   

    jdom9支持xpath,或许是你的版本问题
    下面这段程序可以运行
    import java.io.*;
    import java.util.*;
    import org.jdom.*;
    import org.jdom.input.*;
    import org.jdom.output.*;
    import org.jdom.xpath.*;
    import org.saxpath.SAXPathException;public class XPathReader {  public static void main(String[] args) throws IOException, JDOMException
    {
           
            String filename = "input/customers.xml";
            PrintStream out = System.out;        SAXBuilder builder = new SAXBuilder();
            Document doc = builder.build(new File(filename));     
             XPath customers = XPath.newInstance("//Customers");
             List customer = customers.selectNodes(doc);
             Iterator i = customer.iterator();
             while (i.hasNext()) {
                 Element servlet = (Element) i.next();
                 out.println("\t" + customer.getAttributeValue("CustomerID"));     //output attribute
                 out.println(customer.getAttributeValue("CompanyName"));           
             }        
        }
    }