/aaa[namespace-uri()="http://www.dom4j.org"] won't work in plain XPath. The name step 'aaa' with no prefix matches nodes with local name 'aaa' in no namespace. You could instead use (as does dom4j in the getPath() method):
/*[local-name()="aaa" and namespace-uri()="http://www.dom4j.org"] Not pretty but it works. -- Steen -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Wannheden, Knut Sent: 25. februar 2003 09:14 To: [EMAIL PROTECTED] Cc: 'Igor Akkerman' Subject: RE: [dom4j-user] XPath w/ Namespace By default, IIRC, the namespace mappings used in the XPath expression are the same as those in the Document you run the query against. But using plain XPath you could do something like this): /aaa[namespace-uri(.) = 'http://www.dom4j.org']/bbb[namespace-uri(.) = 'http://www.dom4j.org'] alternatively (using the dom4j api) you could also do something like this: XPath xp = DocumentFactory.getInstance().createXPath("/foo:aaa/foo:bbb"); Map nsMap = new HashMap(); nsMap.put("foo", "http://www.dom4j.org"); xp.setNamespaceURIs(nsMap); xp.selectNodes(yourContextNode); Hope this helps, -- knut > -----Original Message----- > From: Igor Akkerman [mailto:[EMAIL PROTECTED] > Sent: Dienstag, 25. Februar 2003 07:52 > To: [EMAIL PROTECTED] > Subject: [dom4j-user] XPath w/ Namespace > > > Hi, > > how do I address an element with an xpath that has a > namespace not knowing > what prefix is set for the namespace? > > Here is an example document: > <nsa:aaa > xmlns:nsa="http://www.dom4j.org"><nsa:bbb>foo</nsa:bbb></nsa:aaa> > > I used the xpath expression "/nsa:aaa/nsa:bbb" to get the > nsa:bbb element. > But what if the document looks like this? > <nsb:aaa > xmlns:nsb="http://www.dom4j.org"><nsb:bbb>foo</nsb:bbb></nsb:aaa> > > The second document is absolutely equivalent to the first since the > namespace prefix is only symbolic for the url which is equal for both > documents. Also the following document is equivalent: > <aaa xmlns="http://www.dom4j.org"><bbb>foo</bbb></aaa> > > How can I ignore the prefix for addressing elements? (The document may > contain two or three different namespaces, so I cannot only > use the local > name!) > > Igor > > > > > ------------------------------------------------------- > This sf.net email is sponsored by:ThinkGeek > Welcome to geek heaven. > http://thinkgeek.com/sf > _______________________________________________ > dom4j-user mailing list > [EMAIL PROTECTED] > https://lists.sourceforge.net/lists/listinfo/dom4j-user > ------------------------------------------------------- This sf.net email is sponsored by:ThinkGeek Welcome to geek heaven. http://thinkgeek.com/sf _______________________________________________ dom4j-user mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/dom4j-user