Skip to content

Instantly share code, notes, and snippets.

@ManasJayanth
Last active December 28, 2015 18:09
Show Gist options
  • Save ManasJayanth/7540773 to your computer and use it in GitHub Desktop.
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
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