Read and Parse XML web resource using Jscript – CRM 2011

Rajeev Pentyala - Dynamics CRM Blog

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

Advertisements

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s