The mobile application I'm currently developing utilizes XML dataisland files for retrieving dropdown data. The snippet below showcases the code defining the file:
<xml id="DefaultDataIslands" src="../XMLData/DataIslands-<%=((User.Identity).Database)%>.xml">
</xml>
Here is an example code segment demonstrating the use of these XML dataislands:
var oDataIsland = document.getElementById("DefaultDataIslands");
var oXmlNodes = oDataIsland.XMLDocument.selectNodes("XMLDataIslands/DataIsland[@ID='DIMRGroup']/Option");
This line involving oDataIsland is repeated around 4000 times throughout the application. Being an intranet-based app, I can prompt users to directly download the XML files. The main goal here is to minimize necessary adjustments while eliminating all XML tags. It's crucial that the application functions smoothly on Chrome upon completion.
I consulted a resource from mozilla regarding dataislands: https://developer.mozilla.org/en/docs/Using_XML_Data_Islands_in_Mozilla
Below you'll find a revised piece of code based on the information provided by mozilla:
var doc = document.getElementById(strDataSource).contentDocument;
var mainNode = doc.getElementsByTagName("DataIsland");
var oXmlNodes;
var strOptions = "";
for (i = 0; i < mainNode.length; i++) {
if (mainNode[i].getAttributeNode("ID").nodeValue == strDataMember) {
oXmlNodes = mainNode[i].getElementsByTagName("Option");
}
}
The code effectively gathers data and operates seamlessly in IE (10 with standard mode, no quirks). Implementing this change in the overall solution was relatively straightforward.
The only hiccup is that the
line encounters issues in Chrome. This property is undefined on Chrome despite being mentioned in Mozilla's documentation.document.getElementById(strDataSource).contentDocument;
I'm seeking alternative suggestions to resolve this. I've attempted various methods such as using HTTPRequest (resulting in excessive requests per page), transitioning to JSON (which necessitates revamping existing methods entirely), or shifting XML processing to the backend instead of client-side (calling for architectural changes). Unfortunately, none of these approaches have yielded positive results so far.
Are there any other techniques I could explore? Or should I concentrate solely on rectifying the contentDocument
conundrum?