PhpRiot
News Archive
PhpRiot Newsletter
Your Email Address:

More information

Lorna Mitchell's Blog: Fetching Namespaced XML Elements With SimpleXML

Note: This article was originally published at PHPDeveloper on 5 November 2010.
PHPDeveloper

Lorna Mitchell has a new post to her blog with a quick example of how to get namespaced values with SimpleXML out of a properly formatted XML file.

Recently I was working with some google APIs and needed to retrieve some namespaced elements from the result set. This confused me more than I expected it to so here's my code for the next time I need it (and if you use it too, then great!) I was reading from their analytics data feed API, this returns a few key fields and then multiple tags, each with namespaced children.

The trick is to grab the current document's namespaces (via getNamespaces), finding the key for the ones you want and grabbing them as children.