Reputation: 6694
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
Reputation: 972
selectNode() is not on javascript, you meant that you are looking for equivalent function?
nodes.getElementsByTagName("tagname");
Upvotes: 1
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