bugKawa - Bugs: bug #23176, XMLNS seems to break XQuery

 
 

bug #23176: XMLNS seems to break XQuery

Submitter:  Art Bugorski <artbugorski>
Submitted:  Mon 05 May 2008 07:09:29 PM UTC
   
 
Category:  None Severity:  3 - Normal
Item Group:  None Status:  Invalid
Privacy:  Public Assigned to:  bothner
Open/Closed:  Closed
* Mandatory Fields

Add a New Comment Rich Markup
   

Tue 06 May 2008 04:11:02 PM UTC, comment #3: 

I thought I'd post the complete solution for anyone who may come across this issue by having the same problem two proper working solutions are

[code]
declare namespace h = "http://www.w3.org/1999/xhtml";
let $d := doc("xq_test.html")//h:p/text()
return $d = "pass"
[/code]

or

[code]
declare default element namespace "http://www.w3.org/1999/xhtml";
let $d := doc("xq_test.html")//p/text()
return $d = "pass"
[/code]

The [code]doc("xq_test.html")//*:p/text()[/code] solution mentioned by bothner is not semantically correct since it selects any 'p' (i.e. from ANY namespace an thus not necessarily just paragraph tags from HTML, but since there is only HTML in this document it will work in this case. Should you however embed another XML document into this one and shold that document have a 'p' tag then that would also get selected.

Art Bugorski <artbugorski>
Mon 05 May 2008 08:28:50 PM UTC, comment #2: 

Thank you for the reply. I'm just surprised I never came across that before... though come to think of it I've just never used XQuery with documents that used namespaces. Once again, thanks!

Art Bugorski <artbugorski>
Mon 05 May 2008 07:52:31 PM UTC, comment #1: 

This is correct.  The 'p' in the XQuery program means to match against an element p in the "default element namespace", which is the empty namespace.

http://www.w3.org/TR/xquery/#node-tests
"An unprefixed QName, when used as a name test on an axis whose principal node kind is element, has the namespace URI of the default element/type namespace in the expression context; otherwise, it has no namespace URI."

Since you haven't defined a default element namespace, the default for the default element namespace is the empty namespace, which doesn't match "http://www.w3.org/1999/xhtml".
You can set the default element namespace as described here:
http://www.w3.org/TR/xquery/#id-default-namespace

Note if you want to match 'p' in any namespace, you can write *:p as in:
doc("xq_test.html")//*:p/text()

Per Bothner <bothner>
Group administrator
Mon 05 May 2008 07:09:29 PM UTC, original submission:  

Running the following code on the attached XHTML document (which validates) produces the result "false". However, if the "xmlns" in the HTML tag is removed or renamed (adding another 'x' to the beginning suffices) the query returns true. Because my knowledge of XQuery, perhaps this is not an actual bug but the result of some minutae in the specifications, but it seems very peculiar and was very frustrating until it was discovered and does not seem like it is correct to me.

If this is actually the intended result  any explanation, or link to spec, or correction to the query, would be appreciated, but from all that I've read and from my understanding of XQuery this should not happen. 

[code]
let $d := doc("xq_test.html")//p/text()
return $d = "pass"
[/code]

Art Bugorski <artbugorski>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

Attached Files
file #15612:  xq_test.html added by artbugorski (293B - text/html)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by bothner (Posted a comment)
  • -email is unavailable- added by artbugorski (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only logged-in users can vote.

     

    Follow 4 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2008-05-05 bothner StatusNone Invalid
        Assigned toNone bothner
        Open/ClosedOpen Closed
    2008-05-05 artbugorski Attached File- Added xq_test.html, #15612

    Back to the top

    Powered by Savane 3.13-4b48.
    Corresponding source code