Skip to content Skip to sidebar Skip to footer

Difference In Jquery With Xml Namespace And Xhr.responsexml Between Opera And Firefox

Consider this: XML-problem

Solution 1:

It's not a bug in Opera. It's the correct behavior:

In a namespace-aware client, the name part of element type selectors (the part after the namespace separator, if it is present) will only match against the local part of the element's qualified name.

In your case local name is x, and atom:xisn't even a legal local name in XML.

Moreover, namespace-prefixed type selector in CSS has different syntax that doesn't use colon at all:

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

Your syntax seems to rely on a quirk introduced by HTML parsers in namespace-unaware user-agents.

HTML parser "eats" the colon as part of tag name and you get atom:x element in default namespace, which would match atom\:x selector, but in XML that you get x element in http://www.w3.org/2005/Atom namespace.

Solution 2:

I've already experienced this behavior in different versions of the same browser and as far as I remember at the time I was testing the problematic page with FF and IE, so I'd say it's not an Opera-specific bug.

I'd suggest that whenever you use jQuery for parsing XML tags with namespace prefixes, you query for the selector both with and without the prefix. That is, instead of using

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

try

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

I think this is an acceptable workaround for most situations and it will assure that your results are correct despite the misbehaviors...

Solution 3:

I think you should say "atom:x" (without the backslashes), and be sure to have the xmlns:atom="http://www.w3.org/2005/Atom" declaration either on the html tag on the main html file, or in some other way known for the javascript.

Solution 4:

It is hard to say if this is a bug in opera or if this is a bug in jQuery that is Opera specific. From the sounds of it, Opera is not properly adding the namespace to the xhr document dom and this is why jQuery cannot query atom:x and also explains why, when you create your own jquery node, you do not get the same results.

First thing I would do is to try and see if atom is a defined namspace in the xhr dom. It should return your atom ns as defined, If not, this is probably an opera bug. I'm not sure the best way to test this, but perhaps: xhr.getElementByTagNameNS( "x" "http://www.w3.org/2005/Atom" ); will work.

Failing that, Opera claims to support XML namespaces fully however so, I would open a bug request with jQuery and see where that get's you.

In other points, as I eluded to in my comment, I do not think that querying atom:x by x is a good idea at all. You may as well not use namespaces since it defeats the purpose.

Post a Comment for "Difference In Jquery With Xml Namespace And Xhr.responsexml Between Opera And Firefox"