• 08:36 PM

How to use SimpleXML parsing XML data with namespace and CDATA

There are many social network websites (e.g. YouTube) and big brand websites(e.g. Amazon, Yahoo) use REST or SOAP or even RSS web services to provide the enormous data for developers. Using these data, we can build a website virtually with no own database at all, all the information are come from these big sites. The nice thing is that, virtually all of the data returned for your web service client request are a XML data stream. So, we can use the nice PHP5 built in SimpleXML object to parsing the XML data stream, and format the representation of the data according our own website needs. However, the XML data format vary from site to site, some of the XML data returned from the sever, includes namespace and CDATA; if this is the case, you need find a way to access a sub item in the XML data use the same ” -> ” syntax. (more…)

last comments ...
clonks
clonks

Thanks! GREAT!
jcvangent
jcvangent

To speed things up (since I only want the description),if I do an: $entry->children('http://search.yahoo.com/mrss/')->group->description; It…
jcvangent
jcvangent

even when doing it like the example above it gives me an empty string: $media =…
David Adam
David Adam

Are you sure the live feed you got is in correct format. Here is the code I run on the…
jcvangent
jcvangent

What is the url you are using for getting the xml feed, currently I'm using 'http://gdata.youtube.com/feeds/base/videos/-/dance' for example as a…