Querying element by names with xpath returns empty results in application/xhtml+xml type

RESOLVED INVALID

Status

()

RESOLVED INVALID
12 years ago
12 years ago

People

(Reporter: medikoo+mozilla.org, Unassigned)

Tracking

1.8 Branch
x86
Windows XP
Points:
---

Firefox Tracking Flags

(Not tracked)

Details

(URL)

(Reporter)

Description

12 years ago
User-Agent:       Mozilla/5.0 (Windows; U; Windows NT 5.1; pl; rv:1.8.0.7) Gecko/20060909 Firefox/1.5.0.7
Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 5.1; pl; rv:1.8.0.7) Gecko/20060909 Firefox/1.5.0.7

Any query for element with specific name like '//body' will return empty result, when document is of application/xhtml+xml type.
Queries that doesn't address specific element names returns expected values. Like '//*' will return expected result.

Reproducible: Always

Steps to Reproduce:
1.Create empty xhtml document
2.add js script line:
alert(document.evaluate('count(//body)', document, null, XPathResult.NUMBER_TYPE, null).numberValue);
3. Run document as application/xhtml+xml type

Actual Results:  
alert box will throw '0'

Expected Results:  
alert box should show '1'

Doesn't occur with text/html type.
(Reporter)

Updated

12 years ago
Component: General → DOM
Product: Firefox → Core
Version: unspecified → 1.8 Branch

Updated

12 years ago
Assignee: nobody → general
QA Contact: general → ian

Comment 1

12 years ago
Your test case uses a namespace and Firefox is correctly disregarding <body xmlns="http://www.w3.org/1999/xhtml"> elements because your XPath is asking for plain <body> elements.

To use the namespace, include a prefix in your XPath and supply a function as the third argument to document.evaluate() to translate the prefix into the namespace. This, for instance:

alert(document.evaluate('count(//html:body)', document, function(prefix){return (prefix == 'html' ? 'http://www.w3.org/1999/xhtml' : '');}, XPathResult.NUMBER_TYPE, null).numberValue);

See http://www.w3.org/TR/DOM-Level-3-XPath.
(Reporter)

Comment 2

12 years ago
Thanks for that explanation.
I wasn't aware of that.
Sorry for invalid submit. I'm changing status to INVALID
Status: UNCONFIRMED → RESOLVED
Last Resolved: 12 years ago
Resolution: --- → INVALID
You need to log in before you can comment on or make changes to this bug.