Have you not read our ongoing debate?  It's very related.  :-)

Basically, the answer is 'no', but I think it should be 'yes'.  If 
you're bold enough to remove the namespaces, take a look at code here:

http://www.mail-archive.com/dom4j-user%40lists.sourceforge.net/msg02511.html

--Evan


S. Sharif wrote:
> Sorry, please ignore my previous e-mail.  You already
> provided the correct solution.  I tried it and it
> works.
>
> One more last question.  Is it always necessary to
> specify the namespace in order for the XPath to work? 
> Is there a way for me to ignore the namespace and just
> have the XPath work without looking at the namespace?
>
> For example, what if I want the following XPath
>
> "Document/[EMAIL PROTECTED]'Primary']/LOGIN/USERID"
>
> to work on both the following XML documents:
>
> An xml document not specifying any namespace
>
> <Document>
>   <LOGIN_LIST filter="Primary">
>     <LOGIN>
>       <USERID>testuser1</USERID>
>       <PASSWORD>novell</PASSWORD>
>     </LOGIN>
>   </LOGIN_LIST>
> </Document>
>
> as well as those xml documents who happen to specify a
> default namespace for the entire document, such as
>
> <Document
> xmlns="http://www.nget.com/coreapps/RunDVPRequest";>>
>   <LOGIN_LIST filter="Primary">
>     <LOGIN>
>       <USERID>testuser1</USERID>
>       <PASSWORD>novell</PASSWORD>
>     </LOGIN>
>   </LOGIN_LIST>
> </Document>
>
> Can't I use a single XPath
> "Document/[EMAIL PROTECTED]'Primary']/LOGIN/USERID"
> to work for both situations?
>
> Thanks.
>
>
> --- Edwin Dankert <[EMAIL PROTECTED]> wrote:
>
>   
>> This doesn't work, instead you will have to define a
>> prefix for the
>> namespace, it does not matter that the prefix in you
>> code does not
>> match the one in the XML document (actually the code
>> wouldn't be very
>> portable if this had to be case)!
>>
>>     
>>> try {
>>>   HashMap<String, String> map = new
>>>       
>> HashMap<String, String>();
>>     
>>>   // usually I put the prefix here as the first
>>>       
>> parameter
>>
>>     map.put("we",
>> "http://www.nget.com/coreapps/RunDVPRequest";);
>>
>>     
>>     XPath xpath = new
>>
>>     
> Dom4jXPath("we:Document/we:[EMAIL PROTECTED]'Primary']/we:LOGIN/we:USERID");
>   
>>>  xpath.setNamespaceContext(new
>>>       
>> SimpleNamespaceContext(map));
>>     
>>>  return xpath.selectNodes(_xml);
>>>  } catch (JaxenException e) {
>>>    System.err.println("Trouble with Jaxen...");
>>>    return null;
>>>  }
>>>       
>> Regards,
>> Edwin
>> -- 
>> http://www.edankert.com/
>>
>>
>>     
> -------------------------------------------------------------------------
>   
>> Take Surveys. Earn Cash. Influence the Future of IT
>> Join SourceForge.net's Techsay panel and you'll get
>> the chance to share your
>> opinions on IT & business topics through brief
>> surveys - and earn cash
>>
>>     
> http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
>   
>> _______________________________________________
>> dom4j-user mailing list
>> dom4j-user@lists.sourceforge.net
>>
>>     
> https://lists.sourceforge.net/lists/listinfo/dom4j-user
>   
>
>
> **********************************************************
> * Saladin Sharif
> * e-mail:  [EMAIL PROTECTED]
> * Visit homepage @ http://gaia.ecs.csus.edu/~sharifs
> **********************************************************
>
>
>  
> ____________________________________________________________________________________
> Food fight? Enjoy some healthy debate 
> in the Yahoo! Answers Food & Drink Q&A.
> http://answers.yahoo.com/dir/?link=list&sid=396545367
>
> -------------------------------------------------------------------------
> Take Surveys. Earn Cash. Influence the Future of IT
> Join SourceForge.net's Techsay panel and you'll get the chance to share your
> opinions on IT & business topics through brief surveys - and earn cash
> http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
> _______________________________________________
> dom4j-user mailing list
> dom4j-user@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/dom4j-user
>   


-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
dom4j-user mailing list
dom4j-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/dom4j-user

Reply via email to