[jdom-interest] XPath and Namespaces

Laurent Bihanic laurent.bihanic at atosorigin.com
Fri Jul 26 04:24:59 PDT 2002


Hi,

 From the Javadoc of Jaxen's NamespaceContext: "In XPath, there is no such 
thing as a 'default namespace'. The empty prefix *always* resolves to the 
empty namespace URI."

I haven't verified against the XPath spec but this clearly indicates you can't 
use "" as namespace prefix in XPath.
You should fill a bug against Jaxen requesting XPath.addNamespace to throw an 
exception if the passed namespace prefix is empty.

Laurent

Carsten Karkola wrote:
> 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
> 
> _______________________________________________
> To control your jdom-interest membership:
> http://lists.denveronline.net/mailman/options/jdom-interest/youraddr@yourhost.com
> 

-- 
                  wWw    Zzzzz
                 (- -)
-------------ooO-(_)-Ooo-----------------------------------------------
Laurent Bihanic           | Tel: +33 (0)1 55.91.21.93  (Direct line)
Atos Origin               |      +33 (0)1 55.91.20.00
Intégration - e-Business  | Fax: +33 (0)1 55.91.22.31
Les Miroirs - Bat. C      |
18, avenue d'Alsace       |
F-92926 La Defense Cedex  | e-Mail: laurent.bihanic at atosorigin.com
-----------------------------------------------------------------------

"Microsoft isn't the answer. Microsoft is the question and the answer
  is no."


DISCLAIMER:
The opinions expressed are entirely my own and may not necessarily be
those of my employer.  Also, I am not now nor have I ever been a
lawyer.  My opinions are provided as-is with absolutely no warrantee of
merchantability or fitness for any particular use.  Besides, you can't
prove I typed this.  No body saw me type this.  Who says I typed this?




More information about the jdom-interest mailing list