Difference in jQuery with XML and xhr.responseXML namespace between Opera and Firefox

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. ? , , ?


:

  • ? , , ?
  • Opera? , ?

, :)

+5
4

Opera. :

, , ( , ) .

x atom:x XML.

, namespace-prefixed type selector CSS , :

@namespace atom url(http://www.w3.org/2005/Atom);
atom|x { color: blue }

, , , HTML , .

HTML- "" , atom:x , atom\:x, XML x http://www.w3.org/2005/Atom.

+3

, , , FF IE, , Opera.

, , jQuery XML , , .

var x_txt = xml.find('atom\\:x').text();

var x_txt = xml.find('atom\\:x, x').text();

, , , , ...

+2

, "atom: x" ( ), xmlns: atom = "http://www.w3.org/2005/Atom" html html - , javascript.

+1

, ​​ jQuery, Opera. Opera xhr document dom, JQuery atom: x, , , jquery node, .

, , , namspace xhr dom. ns, , , , , . , , : xhr.getElementByTagNameNS( "x" "http://www.w3.org/2005/Atom" ); .

Opera , XML, jQuery , .

, , , atom:x x - . , .

0

All Articles