Hi,
that is because your XPath statement operates on the default
namespace (xmlns="") and when you set a different default namespace
in your document the query will yield "null" as a result of the
selectSingleNode method and your getText() will not work on null.
Note that I only tried the following to define namespace prefixes,
never to change the default namespace... but it probably would look
something like this:
try {
HashMap<String, String> map = new HashMap<String, String>();
// usually I put the prefix here as the first parameter
map.put("", "http://www.nget.com/coreapps/RunDVPRequest");
XPath xpath = new Dom4jXPath(xpathstring);
xpath.setNamespaceContext(new SimpleNamespaceContext(map));
return xpath.selectNodes(_xml);
} catch (JaxenException e) {
System.err.println("Trouble with Jaxen...");
return null;
}
Cheers
Richard
Am 18.01.2007 um 00:07 schrieb S. Sharif:
Hi,
The following piece of code works fine
primaryUserId =
inputDocument.selectSingleNode("Document/LOGIN_LIST
[EMAIL PROTECTED]'Primary']/LOGIN/USERID").getText();
for the following xml tree
<pre>
<Document>
<LOGIN_LIST filter="Primary">
<LOGIN>
<USERID>testuser</USERID>
<PASSWORD>somepassword</PASSWORD>
</LOGIN>
</LOGIN_LIST>
</Document>
</pre>
But when the above xml tree is modified by adding an
xmlns attribute to the root "Document" element, the
code no longer works and it throws a
NullPointerException
<pre>
<Document
xmlns="http://www.nget.com/coreapps/RunDVPRequest">
<LOGIN_LIST filter="Primary">
<LOGIN>
<USERID>testuser</USERID>
<PASSWORD>somepassword</PASSWORD>
</LOGIN>
</LOGIN_LIST>
</Document>
</pre>
Why is it no longer working? The XPath expression
should still work?
**********************************************************
* Saladin Sharif
* e-mail: [EMAIL PROTECTED]
* Visit homepage @ http://gaia.ecs.csus.edu/~sharifs
**********************************************************
________________________________________________________________________
____________
8:00? 8:25? 8:40? Find a flick in no time
with the Yahoo! Search movie showtime shortcut.
http://tools.search.yahoo.com/shortcuts/#news
------------------------------------------------------------------------
-
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
[email protected]
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
[email protected]
https://lists.sourceforge.net/lists/listinfo/dom4j-user