[jdom-interest] XPATH and namespace

Kevin L. Cobb kevin.cobb at emergint.com
Fri Sep 2 13:23:23 PDT 2005


Well, as usual, I'll answer my own question. 
 
Seems that XPath can't handle namespace prefixes all by its lonesome. If
you have an expression that has namespace prefixes, you have to indicate
the namespaces in the XPath object. Like so:
 
         XPath conditionXpath =
XPath.newInstance("//ruleDef/ilog:conditions[1]/text()");
         conditionXpath.addNamespace("ilog", "http://www.myrules.com
<http://www.myrules.com/> ");

-Kevin

________________________________

From: jdom-interest-bounces at jdom.org
[mailto:jdom-interest-bounces at jdom.org] On Behalf Of Kevin L. Cobb
Sent: Friday, September 02, 2005 2:05 PM
To: jdom-interest at jdom.org
Subject: [jdom-interest] XPATH and namespace


Having trouble getting an XPATH expression with a namespace identifier
to retreive the value in the XPATH. Example:
 
 
<ruleDef  xmlns:ilog="http://www.myrules.com">
   <ilog:conditions conditionId="condID_590"
ruleId="rule_590">3</ilog:conditions>
 </ruleDef>

The XPATH expression "//ruleDef/ilog:conditions[1]/text()" does not
return a result. I expect 3 to be the result. 
 
 
 
Thanks,
 
Kevin
 
 

 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.jdom.org/pipermail/jdom-interest/attachments/20050902/ad46d744/attachment.htm


More information about the jdom-interest mailing list