Read and Parse XML web resource using Jscript – CRM 2011

Rajeev Pentyala - Microsoft Power Platform

I have a XML file with below content added as a web resource (new_fruitsxml) in my CRM application

<?xml version=”1.0″ encoding=”utf-8″ ?>

<Fruits>

<Fruit Code=”App”>

<Name>Apple</Name>

<Price>20</Price>

</Fruit>

<Fruit Code=”Orng”>

<Name>Orange</Name>

<Price>10</Price>

</Fruit>

</Fruits>

Below is the Jscript code to read and parse the XML.

Note– The code uses JQuery to parse the XML, so you have to refer “jquery1.4.1.min.js” file to make the code works.

function ReadXML() {

try {

var xmlPath = “../WebResources/new_fruitsxml”;

$.ajax({

type: “GET”,

url: xmlPath,

dataType: “xml”,

success: parseXML

});

} catch (e) {

alert(“Error while reading XML; Description – ” + e.description);

}

}

function parseXML(xml) {

$(xml).find(“Fruit”).each(function () {

// Read attribute

alert(“Fruit Code – ” + $(this).attr(“Code”));

// Read Nodes

alert(“Fruit Name – ” + $(this).find(“Name”).text());

alert(“Fruit Price – ” + $(this).find(“Price”).text());

});

}

  • In “ReadXML()” function we read the webresource and if the read succeeds, we…

View original post 21 more words

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.