From: "Joseph Rajkumar" <[EMAIL PROTECTED]> > Hi > Thanks for your kind reply. But I have one more question on this topic. > > What if my set up is like this: > > xmlns CDATA #FIXED "http://www.somewhere.com/2001/loan" > > In this case how can I query for "//ENTRY" since I do not have a prefix > for this namespace. > > Thanks > Joseph Rajkumar
You must use a namespace prefix in your XPath expression. Note that prefixes used in an XPath expression can be independent of those used in the document itself. e.g. using the current daily build of dom4j (the new 1.2 release will be out soon) Map uris = new HashMap(); uris.put( "loan", "http://www.somewhere.com/2001/loan" ); XPath xpath = document.createXPath( "//loan:ENTRY" ); xpath.setNamespaceURIs( uris ); List entries = xpath.selectNodes( document ); In the above code this would match any ENTRY element in any document provided the namespace URI matched the one given - irrespective of what prefix was used. So in the following document the above code would match the first 2 <ENTRY> elements but not the third, since only the namepspace URI is important. <foo> <ENTRY xmlns="http://www.somewhere.com/2001/loan"/> <bar:ENTRY xmlns:bar="http://www.somewhere.com/2001/loan"/> <loan:ENTRY xmlns:loan="http://www.acme.com/somethingElse"/> </foo> James > > James Strachan wrote: > > > > Hi Joseph > > > > This sounds like a namespace issue. Does your XML document look something > > like this... > > > > <foo xmlns="something"> > > <ENTRY> > > ... > > </ENTRY> > > </foo> > > > > i.e. that the <ENTRY> elements are all in some namespace? If so, then this > > is correct behaviour. To match elements in a namespace you must use either > > the functions name(), local-name() and namespace-uri() to match nodes or use > > namespace prefixes in your XPath expression. > > > > e.g. you could use > > > > //my:ENTRY > > > > if you had bound the 'my' prefix to the namespace URI thats used in your XML > > document. > > > > James > > ----- Original Message ----- > > From: "Joseph Rajkumar" <[EMAIL PROTECTED]> > > To: <[EMAIL PROTECTED]> > > Sent: Thursday, December 27, 2001 5:48 PM > > Subject: Re: [dom4j-user] Issue with dom4j 1.1 > > > > > Hi > > > Just a quick question for you: > > > > > > I am trying to use dom4j for a project and when I try: > > > > > > This XPath returns zero nodes ==> "//ENTRY" > > > > > > Whereas this returns the correct values: ==> "//*[name()='ENTRY']" > > > > > > Has there been some radical change or am I missing some thing. > > > > > > Regards > > > Joseph Rajkumar > > > > _________________________________________________________ > > Do You Yahoo!? > > Get your free @yahoo.com address at http://mail.yahoo.com _________________________________________________________ Do You Yahoo!? Get your free @yahoo.com address at http://mail.yahoo.com _______________________________________________ dom4j-user mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/dom4j-user
