Last active
December 28, 2015 18:09
-
-
Save ManasJayanth/7540773 to your computer and use it in GitHub Desktop.
Code for StackOverflow question (http://stackoverflow.com/questions/20063968/xml-get-attributes-javascript-doesnt-work-on-childnodes) - xml get attributes javascript doesn't work on childNodes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if (window.XMLHttpRequest){ | |
// code for IE7+, Firefox, Chrome, Opera, Safari | |
xmlhttp=new XMLHttpRequest(); | |
} | |
else { | |
// code for IE6, IE5 | |
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); | |
} | |
xmlhttp.open("GET","maps/kmap.svg",false); | |
xmlhttp.send(); | |
xmlDoc=xmlhttp.responseXML; | |
console.log('-------path method----------'); | |
var node = xmlDoc.getElementById('g67'); | |
console.log(node); | |
for(var i = 0; i < node.getElementsByTagName('path').length; ++i) { | |
console.log(node.getElementsByTagName('path')[i].getAttribute('d')); | |
} | |
console.log('-----------------'); | |
console.log('--------child method---------'); | |
var node = xmlDoc.getElementById('g67'); | |
console.log(node); | |
for(var i = 0; i < node.childNodes.length; ++i) { | |
console.log(node.childNodes[i].getAttribute('d')); | |
} | |
console.log('-----------------'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment