Solved

javascript parse xml without jquery

Posted on 2013-05-17
1
668 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
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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Introduction Chart.js, used properly, can visually add a difference to your charting applications. It engages your visitors and allows them to interact with data they otherwise wouldn't be able to without expensive and complicated systems. For this…
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. 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…

820 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