ExtJS, XML, and the DOM

So I’m trying to get this XML in use with my ExtJS Store and Grid, when i switch over to IE to test (Firefox was working fine), and I’m getting all these syntax errors and such.

“Great!”, I said as I looked up to the clock looming at my current deadline.

Feeding just the string to an Ext.data.XmlStore had been just fine with FireFox, but IE, no, of course not IE.

My store went as follows:

var gridStore = new Ext.data.XmlStore({
// store configs
autoDestroy: true,
storeId: 'gridStore',
data: xmlData.toString(),
// reader configs
record: 'item[@type="book"]',
idPath: 'isbn',
fields: [
'isbn', 'author', 'title'
]
});

So, now with IE, I have to make an official XML object from what i get back from the server side.

Using this conditional, I can now get what i need for both FireFox and IE.

// <![CDATA[
var xmlDoc;
if (window.DOMParser)
{
parser=new DOMParser();
xmlDoc=parser.parseFromString("","text/xml");
}
else // Internet Explorer
{
xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async="false";
xmlDoc.loadXML("");
}
// ]]>

So, now, for the ExtJS Store, I just had to use the xmlDoc object instead of the hacked XML string I aquired by my own making (var xmlData = ““;).

I just replace the Store – data Config Propery with this:
data: xmlDoc, and IE is good to go.

“The Code shall make the world go ’round”,
JavaClaus 10.12.10

About javaclaus

Java Programmer, Code master, mountain biker, snowboarder, etc.
This entry was posted in ExtJS, JavaScript. Bookmark the permalink.

Leave a comment