Solved

javascript parse xml without jquery

Posted on 2013-05-17
1
607 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
Comment Utility
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This article discusses how to create an extensible mechanism for linked drop downs.
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)

772 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now