Solved

javascript parse xml without jquery

Posted on 2013-05-17
1
755 Views
Last Modified: 2013-05-18
Hi,
I just wrote a function (with help) to parse some xml.  How can I do this without jquery?

function getValueFromXml(xml, key) {
    xmlDoc = $.parseXML(xml);
    $xml = $(xmlDoc);
    $returnValue = $xml.find(key);
    return $returnValue;
}
0
Comment
Question by:jackjohnson44
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 35

Accepted Solution

by:
Robert Schutt earned 500 total points
ID: 39176328
With most new browsers this should work (tested in FireFox and Chrome):
function getValueFromXml(xml, key) {
	var parser = new DOMParser();
	var xmlDoc = parser.parseFromString(xml, "text/xml");
	var sessionIdNodes = xmlDoc.getElementsByTagName(key);
	return sessionIdNodes.length ? sessionIdNodes[0].textContent : 'NOT_FOUND';
}

Open in new window

0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are a couple ways to attach a JavaScript function to dynamically created elements. You can make a new script for each element as it’s created or you can use delegation. Delegation allows a single script that is added at page creation to mat…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
Suggested Courses
Course of the Month10 days, 22 hours left to enroll

628 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question