Solved

javascript parse xml without jquery

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

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.
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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…
Suggested Courses

751 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