How to read XML file in Dynamics CRM 2011 using Javascript.

In Dynamics CRM 2011, we could maintain the XML files using web resource utility, which is a very good feature. It could be read using Javascript which is also maintained in the web resources of Dyanmics CRM 2011.You could make use of this feature when you want to populate some values dynamically.

Sample xml file –Configuration.xml
<Configurations>
<Configuration id=”Code”>C0001</Configuration>
<Configuration id=”Name”>WebName</Configuration>
</Configurations>

Javascript sample code to read XML File:

var xmlPath = "../WebResources/Configuration.xml";

var xmlnodePath = "//Configurations/Configuration";
var xmldoc = new ActiveXObject("Microsoft.XMLDOM");
xmldoc.preserveWhiteSpace = true;
xmldoc.async = false;
xmldoc.load(xmlPath);
var params = new Array();
var xmlnodelist;
xmlnodelist= xmldoc.selectNodes(xmlnodePath);
for (var i = 0; i < xmlnodelist.length; i++)
{
     params[i] = xmlnodelist(i).attributes[0].value;
}
This entry was posted in MS CRM 2011 and tagged , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *