Kurtainz
Kurtainz

Reputation: 9

Select XML element with colon using plain JavaScript

I'm working with the XML data from Apple's RSS Feed Generator and I've come across a small problem. If I want to select an element from the XML document, normally I would just use querySelector or getElementsByTagName. Unfortunately, this doesn't work if I want to select an element that has a colon in it, for example <im:name>.

I've tried various things like escaping the colon with backslashes (this works with JQuery), but nothing seems to work.

Upvotes: 0

Views: 1319

Answers (1)

Kurtainz
Kurtainz

Reputation: 9

I found I was able to do this by using getElementsByTagName('image') (so omitting the "im:" part of the element tag). This seems to work in all browsers except Firefox (not sure about Safari, don't have access to that at the moment). In Firefox it seems I have to select it with the namespace included, getElementsByTagName('im:image').

Upvotes: 1

Related Questions