[jQuery] Parsing XML using "find()" has stopped working in jQuery 1.3+
Hi, I'm wondering if anyone might be able to shed some light on this
situation.
I have been using jQuery 1.2.6 to parse XML and find specific nodes.
However, when I simply change the jQuery version to 1.3.2 the
following fails to work in IE, though still continues to work fine in
Firefox. Below is a simplified test case which hopefully someone will
be able to comment on.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<script src="jquery-1.3.2.min.js" type="text/javascript"
charset="utf-8"></script>
<script type="text/javascript" charset="utf-8">
// DOM Ready
$(function(){
createInitXMLObj();
/* === test.xml ===
<?xml version="1.0" encoding="UTF-8"?>
<response>
<item>
<name>item 1</name>
<year>2009</year>
<price>9.99</price>
</item>
<item>
<name>item 2</name>
<year>2009</year>
<price>9.99</price>
</item>
<item>
<name>item 3</name>
<year>1999</year>
<price>40</price>
</item>
<item>
<name>item 4</name>
<year>2003</year>
<price>2.00</price>
</item>
</response>
*/
$(xmlInitial).find("item:has(year:contains('2009')):has
(price:contains('9.99'))").each(function(){
alert($(this).children('name').text()); // Should alert "item 1",
"item 2"
})
});// end DOM Ready
/*============= Functions ==============*/
function createInitXMLObj(){
$.ajax({
type: "GET",
url: "test.xml",
dataType: ($.browser.msie) ? "text" : "xml",
async: false,
error: function(e){
alert('error loading xml')
},
success: function(xml){
//work around for IE
var tempXML;
if (typeof xml == "string") {
tempXML = new ActiveXObject("Microsoft.XMLDOM");
tempXML.async = false;
tempXML.loadXML(xml);
xml = tempXML;
}
xmlInitial = xml;
}
});
}
</script>
</head>
<body>
</body>
</html>