Consider this:
<!DOCTYPE HTML>
<html><head><title>XML-problem</title>
<script src="jquery-1.3.2.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(function() {
$('<p/>').load("text.xml", function(responseText, textStatus, xhr) {
var xml = $(xhr.responseXML);
var x_txt = xml.find('atom\\:x').text();
$(this).text(x_txt).appendTo('#container');
});
});
</script>
</head><body><div id="container" /></body></html>
This script should load text.xml when the document has been loaded. text.xml looks like this:
<xml xmlns:atom="http://www.w3.org/2005/Atom">
<atom:x>Text</atom:x>
</xml>
When this file has been loaded, the text contents of the atom:x
-node are appended to the document. I can see "Text" in my browser window.
This works as expected in Firefox. However, it does not work in Opera unless I change the query from 'atom\\:x'
to just 'x'
. In this case it works in Opera, but not Firefox.
I have discovered a workaround, namely changing the query to 'atom\\:x, x'
, but I would rather like to get to the bottom of this.
Now for the funny twist: I can inline the xml directly instead of getting it from XHR by changing
var xml = $(xhr.responseXML);
into
var xml = $('<xml xmlns:atom="http://www.w3.org/2005/Atom"><atom:x>Text</atom:x></xml>');
In this case a query of 'atom\\:x'
will give the desired result in both browsers and just 'x'
will give no result in both browsers.
The fact that this works differently in Opera leads me to conclude that the former behavior is a bug in Opera. Is this a reasonable conclusion? Where can I point to for the standard that describes how this is supposed to work?
In conclusion:
- What are the alternative work-arounds for this problem? Any better than the one I have found?
- Is this a bug in Opera? If yes, which standard says so?
Hope you can help :)