Closed Bug 386119 Opened 17 years ago Closed 17 years ago

javascript evaluate XPath not working if XML has "xmlns=" .

Categories

(Core :: XSLT, defect)

1.8 Branch
x86
Windows 2000
defect
Not set
normal

Tracking

()

RESOLVED INVALID

People

(Reporter: yorichard, Unassigned)

Details

User-Agent:       Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; .NET CLR 1.1.4322; .NET CLR 2.0.50727)
Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.8.1.4) Gecko/20070515 Firefox/2.0.0.4

if the XML root node specify an xmlns="http://somewebsite.com" then the call :

myresults = xmlDoc.evaluate("//mynodename", xNode, Resolver, 0, null) ;

will always return null (except if the xpath is "//." )

Reproducible: Always

Steps to Reproduce:
1. XML :
<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://mywebsite.com">
  <service name="SearchService">
    <port name="SearchPort" binding="typens:SearchBinding">
    </port>
  </service>
</definitions>
2. javascript after Ajax response :
xml= response.responseXML;
var resolver = this.createNSResolver(this.documentElement);
var aItems= xml.evaluate("//service", xml, resolver, 0, null);
var item=aItems.iterateNext();
 var aResult = [];
//for( var i = 0; i < aItems.snapshotLength; i++) 
while(item)
 { 
 aResult.push (item);
 item=aItems.iterateNext();
 } 
alert(aResult.length);
3.the length is always going to be 0.
if you change <definitions xmlns="http://mywebsite.com"> to
<definitions>
then it will work.
IE works fine all the time.
Component: General → XSLT
Product: Firefox → Core
QA Contact: general → xslt
Version: unspecified → 1.8 Branch
XPath doesn't have a default namespace (see third paragraph in http://www.w3.org/TR/xpath#node-tests), so you'll need to use a prefix in the XPath expression and either set a prefix on the elements or have a custom resolver that resolves the prefix.
Status: UNCONFIRMED → RESOLVED
Closed: 17 years ago
Resolution: --- → INVALID
You need to log in before you can comment on or make changes to this bug.