Monday, December 29, 2008

[jQuery] Re: Querying XML with jQuery in IE6

ok, I find that I can get the json element very easy but still haven't found a way to get the attribute name.
$("Test", data).each(function(i){
     console.log($("[@name]", this).text()); // does not work.
     console.log($("json", this).text());  // does work
});
I have tried with the following queries: /Test[@name]
                                                       /Test@name
                                                       Test@name
                                                       .@name

Is this jQuery not supporting attribute selectors or is my xpath wrong?

thanks in advance, jon.

On Tue, Dec 23, 2008 at 4:40 PM, Anonymous <ilaughlouder@gmail.com> wrote:
Hi all.

I'm trying to get some values from an XML document in jQuery but lack of a (good) debugger in IE6 means that I can't figure this out.
The XML is simple:
XML:
                             <Tests>
                                 <Test name="Help">
                                     <json><![CDATA[help.json]]></json>
                                </Test>
                                <Test name="telia-big-box">
                                     <json><![CDATA[telia-big-box.json]]></json>
                                </Test>
                            </Tests>

I get it through jQuery.get and the document is in the variable data:
$("Test", data).each(function(i){
    alert(this.childNodes[0].textContent);
    /*toc.append(
        tc.li(
            testLink(this.childNodes[1].textContent, this.attributes[0].nodeValue)
        )
    );*/
});

The commented bit works in FF3 and I have found that it's the childNodes of the Test element that differs. Is there a safer way to query an XML document with jQuery, so I don't run into these abnormalties between browsers?

Thanks in advance, Jon.

No comments: