Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 348737 - XPath view doesn't pick up default namespace prefix in XPath2-mode
Summary: XPath view doesn't pick up default namespace prefix in XPath2-mode
Status: RESOLVED FIXED
Alias: None
Product: WTP Source Editing
Classification: WebTools
Component: wst.xpath (show other bugs)
Version: 3.3   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: 3.3.1   Edit
Assignee: Jesper Moller CLA
QA Contact: Jesper Moller CLA
URL:
Whiteboard: PMC_approved
Keywords:
Depends on:
Blocks:
 
Reported: 2011-06-08 09:38 EDT by Jesper Moller CLA
Modified: 2011-09-06 10:12 EDT (History)
4 users (show)

See Also:
jesper: pmc_approved? (david_williams)
raghunathan.srinivasan: pmc_approved+
jesper: pmc_approved? (naci.dai)
jesper: pmc_approved? (deboer)
jesper: pmc_approved? (neil.hauge)
jesper: pmc_approved? (kaloyan)
jesper: pmc_approved? (cbridgha)


Attachments
Patch for this issue (1.39 KB, patch)
2011-06-08 09:41 EDT, Jesper Moller CLA
no flags Details | Diff
Patch containing a test case (5.90 KB, patch)
2011-08-31 17:14 EDT, Jesper Moller CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Jesper Moller CLA 2011-06-08 09:38:29 EDT
The XPath view won't pick up default namespace prefixes:

Consider:
<e1 xmlns="urn:x-hello:xpath"><e2/></e1>

For XPath2, the expression "/e1" should then pick up the e1 element, as long as the prefix mappings are set up correctly. Only it doesn't, and that is the bug. 

Side story: For XPath1, however, this is not not the case, it is expressly forbidden:
(from http://www.w3.org/TR/xpath/#node-tests )

Fom 2.3 Node Tests:
[...] A QName in the node test is expanded into an expanded-name using the namespace declarations from the expression context [...] except that the default namespace declared with xmlns is not used: if the QName does not have a prefix, then the namespace URI is null. [...]

So it would be really useful to include a fixed default prefix for the default namepace, i.e. "i.e. always map the default namespace to "default" or "df" so you can at least do //default:server without having to go edit the setup?"
(from http://twitter.com/#!/maxandersen/status/78440623564275712 )
I'm suggesting '_' as the prefix.
Comment 1 Jesper Moller CLA 2011-06-08 09:41:01 EDT
Created attachment 197597 [details]
Patch for this issue

Simple enough patch - still need a test case
Comment 2 David Carver CLA 2011-08-31 09:37:53 EDT
Hey Jesper, any chance of getting this patch committed to head and to the maintenance stream?
Comment 3 Jesper Moller CLA 2011-08-31 11:28:48 EDT
(In reply to comment #2)
> Hey Jesper, any chance of getting this patch committed to head and to the
> maintenance stream?

Yep, there's a chance. I'll get it done in the next few hours.
Comment 4 Jesper Moller CLA 2011-08-31 17:07:54 EDT
Dave: I've committed and released the test and fix for HEAD, but I'd like your review.
Comment 5 Jesper Moller CLA 2011-08-31 17:14:53 EDT
Created attachment 202567 [details]
Patch containing a test case

Simple test case for this bug
Comment 6 Jesper Moller CLA 2011-08-31 17:24:25 EDT
* Explain why you believe this is a stop-ship defect:

This bug makes a very plain and simple usage scenario unusable.

* Is there a work-around?

No workaround except changing the XML document and XPath expressions.

* How has the fix been tested?

Tested manually by me, and excercised by attached JUnit test case.

* Give a brief technical overview.

The XPath2 engine has an API for adding the default namespace, but it needs to be called. It wasn't.

* Who has reviewed this fix? 
I've added David Carver for review.

* What is the risk associated with this fix?

Very small risk since the code change is so simple.
Comment 7 Jesper Moller CLA 2011-08-31 17:25:22 EDT
Oh, I forgot to add, the PMC review is for the Indigo service release, 3.3.1
Comment 8 Jesper Moller CLA 2011-08-31 23:01:38 EDT
Released for 3.3.x.