Skip to content

Instantly share code, notes, and snippets.

@thebouv
Last active August 29, 2015 14:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thebouv/e48265d9b44ab0d9f18b to your computer and use it in GitHub Desktop.
Save thebouv/e48265d9b44ab0d9f18b to your computer and use it in GitHub Desktop.
Parsing XML with namespace (such as slash:comments)
el[0].getElementsByTagNameNS('http://purl.org/rss/1.0/modules/slash/', 'comments')[0].innerHTML;
// or a fuller example
$.get('/blogfeed.php', function (data) {
var count = 1;
$(data).find("item").each(function () {
var el = $(this);
// ...
// how many comments
// textContent must be used instead of innerHTML because webkit returns a NodeList instead of HTMLCollection, and NodeList
// apparently doesn't have innertHTML as a property of the element
var commentCount = parseInt(el[0].getElementsByTagNameNS('http://purl.org/rss/1.0/modules/slash/', 'comments')[0].textContent);
// ...
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment