nagy.zsolt.hun
nagy.zsolt.hun

Reputation: 6694

javascript selectNodes on parsed xml

How can I use the selectNode() function on a parsed XML message in javascript?

<script>
var xmlStr = "<tagName>some text here</tagName>";
var xmlDoc = (new DOMParser()).parseFromString(xmlStr, "text/xml");
var nodes = xmlDoc.selectNodes('tagName');
</script>

I get error for this code: Uncaught TypeError: xmlDoc.selectNodes is not a function

Upvotes: 3

Views: 7897

Answers (2)

The scion
The scion

Reputation: 972

selectNode() is not on javascript, you meant that you are looking for equivalent function?

nodes.getElementsByTagName("tagname");

Upvotes: 1

user6186801
user6186801

Reputation:

Actually XmlDocument.SelectNodes method exists, but in the .NET Framework.

In JavaScript, you can use the getElementsByTagName() method

var nodes = xmlDoc.getElementsByTagName("tagName")[0];

Upvotes: 4

Related Questions