[jdom-interest] XPath and Namespaces
    Carsten Karkola 
    carsten.karkola at mailbox.tu-dresden.de
       
    Fri Jul 26 03:12:22 PDT 2002
    
    
  
I tried to use XPath with jdom.Document:
Document doc = builder.build(filename);
try {
  org.jaxen.XPath path = new JDOMXPath(args[1]);
  path.addNamespace("",doc.getRootElement().getNamespace().getURI());
  List results = path.selectNodes(doc);
  Iterator i = results.iterator();
  while (i.hasNext()) {
   Element elem = (Element) i.next();
   System.out.println("Element: " + elem.getName() );
  }         
  System.out.println(results.size() + " Elements");
 } catch (org.jaxen.JaxenException e) {
     System.err.println(e);
 }
If I use a XPath like //*[2] I will get all the second childs of all my elements 
incl. the <email> element, but if I try to get all child elements by name, there 
are some problems (e.g. //email) - I get no results
I think, it's a namespace problem ?
Thanks for any help.
Carsten
    
    
More information about the jdom-interest
mailing list