In this blog, I have explained the steps to read the XML using JavaScript.
The below XML has Root "Tasks" and nodes "TaskName".
Input XML:
<?xml version="1.0" ?>
<Tasks>
<TaskName id="PromoteBestPractice">Promoted best practices</TaskName>
<TaskName id="PromoteBeneEngage">Promoted beneficiary engagement and self-management</TaskName>
<TaskName id="SustainPlan">Worked on a sustainability plan</TaskName>
</Tasks>
This JavaScript function accepts the xmlPath and xmlnodename as parameters.
JavaScript:
function ChangeLabelTaskNameFrmXML(xmlPath,xmlnodename) {
var request = new XMLHttpRequest();
request.open("GET", xmlPath, false);
request.send();
var xmldoc = request.responseXML;
//Extract the different values using a loop.
var xmlnode = xmldoc.getElementsByTagName(xmlnodename);
// To read the xml nodes in XML file
for (var i = 0; i < xmlnode.length; i++) {
var lbltaskname = xmlnode[i].getAttribute('id');
var newlbltaskname = xmlnode[i].textContent;
alert ("Key:" + lbltaskname + "; Value: " + newlbltaskname );
}
}
Final Output will be displayed in message box with Key and Value as shown below.
Output:
Key: PromoteBestPractice; Value: Promoted best practices
Subscribe to:
Post Comments (Atom)
Augmented Reality and Virtual Reality
Here is the quick overview of Augmented Reality and Virtual Reality, also have explained how it is being used today and how it can chan...
-
As we all know validation is very important for any input forms, Here is a sample for jQuery validation for HTML that can be used for any nu...
-
This video will help you understand the basics of Dynamics CRM in just 5 minutes. Description links: If you like this video, please do...
-
In this blog we are going to see the root cause for performance issues faced in SharePoint List and Libraries. Main reason for the perfor...
No comments:
Post a Comment