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 was 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 content atom:x- node is added to the document. I see “Text” in the browser window.
This works as expected in Firefox. However, it does not work in Opera unless I changed the request from 'atom\\:x'to 'x'. In this case, it works in Opera, but not in Firefox.
I found a workaround, namely changing the request to 'atom\\:x, x', but I would like to dwell on it.
Now for a funny twist: I can embed xml directly and not get it from XHR by changing
var xml = $(xhr.responseXML);
in
var xml = $('<xml xmlns:atom="http://www.w3.org/2005/Atom"><atom:x>Text</atom:x></xml>');
'atom\\:x' , 'x' .
, - Opera, , Opera. ? , , ?
:
, :)