Created
June 29, 2012 05:55
-
-
Save knkumar/3016102 to your computer and use it in GitHub Desktop.
javascript iterate nodeList XML
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
var doc = xhreq.responseText; | |
var parser = new DOMParser(); | |
var link = parser.parseFromString(doc, 'text/xml'); | |
var items = link.documentElement.childNodes; | |
for (var item in items) { | |
if(item.nodeName == 'link'){ | |
for(var attr in item.attributes.name) { | |
if(item.attr.name == 'rel'){ | |
//do something awesome | |
return; | |
} | |
} | |
} | |
} |
But why is there no iterator object on a nodelist maybe we should write one?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
//this code should help you iterate and do something with link tag having rel attribute
var items = xmlDoc.documentElement.childNodes;
for (var index=0;index <items.length; index++) {
if(items[index].nodeName == 'link'){
for(var attrIndex=0; attrIndex < items[index].attributes.length; attrIndex++) {
if(items[index].attributes[attrIndex].nodeName == 'rel'){
//do something awesome
alert("found one link with rel attribute");
}
}
}
}