Skip to content
Advertisement

How to retrieve an attribute from a namespaced element

I am trying to get the url attributes from the <media:content> elements in this RSS feed:

JavaScript

Here’s what I have so far:

JavaScript

This code works for all elements except the ones with a semicolon in the name, like <media:content> or <dc:contributor>. If I open the XML feed in my browser I can see the tag I am looking for:

JavaScript

I tried various solutions from other threads but it didn’t work for me. Example:

JavaScript

I don’t know what I’m doing wrong so I would appreciate some help

Advertisement

Answer

You’re missing a call to the attributes() method of your SimpleXMLElement instance:

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement