Drongo_III Posted August 3, 2012 Share Posted August 3, 2012 Hi Guys I'm pulling an xml feed from Youtube to get some practice with traversing xml. The thing I don't quite get is that when i create an simple xml object and do print_r (to concisely see what's in the xml) it doesn't show everything that's in the actual xml file. Is that usual? And is using print_r on an xml object a stupid idea? For instance this element is missing: <media:thumbnail url="http://i.ytimg.com/vi/6reEBParHzQ/0.jpg" height="360" width="480" time="00:09:41.500"/> $xml = simplexml_load_file('http://gdata.youtube.com/feeds/api/users/JREAMdesign/uploads'); echo "<pre>"; print_r($xml); Quote Link to comment Share on other sites More sharing options...
requinix Posted August 4, 2012 Share Posted August 4, 2012 I think it's a known and reported bug that print_r() doesn't show everything, and especially namespaced stuff. Saw it last week or so. If it's there in the XML then you can access it. $xml->path->to->parent->children("media", true)->thumbnail Quote Link to comment Share on other sites More sharing options...
Drongo_III Posted August 4, 2012 Author Share Posted August 4, 2012 Thanks Req. Least it's not just me being silly then That's a real pain though- can be quite time consuming trying to look through a huge xlm output. Is there a better way to print out all of the xml file as an array? I looked at SimpleXMLIterator which might be useful. Any thoughts? I think it's a known and reported bug that print_r() doesn't show everything, and especially namespaced stuff. Saw it last week or so. If it's there in the XML then you can access it. $xml->path->to->parent->children("media", true)->thumbnail Quote Link to comment Share on other sites More sharing options...
requinix Posted August 6, 2012 Share Posted August 6, 2012 I personally don't like using SimpleXML just to convert the XML into an array. For one you lose out on xpath(). What do you need to do with the XML? Quote Link to comment Share on other sites More sharing options...
Drongo_III Posted August 7, 2012 Author Share Posted August 7, 2012 Well in this instance I am just playing around with pulling in a YouTube feed. It was more just to practice with a large, and fairly complicated, xml file. What would you consider is a good alternative to using simpleXML? Quote Link to comment Share on other sites More sharing options...
requinix Posted August 7, 2012 Share Posted August 7, 2012 What would you consider is a good alternative to using simpleXML? Nothing. SimpleXML is the best thing for XML I've ever found. I've lost track. Is there any problem besides you not knowing what's in the XML? Quote Link to comment Share on other sites More sharing options...
Drongo_III Posted August 7, 2012 Author Share Posted August 7, 2012 Nah it was more just a case of getting some advice on dealing with big xml files as i was using print_r on the object but that, as you pointed out, is bugged. :/ Maybe i just need to polish my eyes Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.