pkrtech Posted August 23, 2006 Share Posted August 23, 2006 Can someone tell me howto or why I cannot seem to grab the description from google video rss feed under element media:description.Any Help appreciated THANKS!Code:$xdom = new domDocument;$cycle = 'http://video.google.com/videofeed?type=search&q=is%3Aforsale&so=1&num=20&output=rss';$xdom->load($cycle); $channel = $xdom->getElementsByTagName("item"); foreach( $channel as $item ) { $xdom->getElementsByTagName("item"); $title = $item->getElementsByTagName( "title" ); $titles = $title->item(0)->nodeValue; $titles = htmlentities($titles, ENT_QUOTES); // this will pull the crappy description that I dont want $descript = $item->getElementsByTagName("description"); $description = $descript->item(0)->nodeValue; $description = htmlentities($description, ENT_QUOTES); //This should pull proper formatted description in media:description but doesnt $break = $xdom->getElementsByTagName("media"); foreach($break as $media) { $break->getElementsByTagName("media"); $descript2 = $media->getElementsByTagName("description"); $description2 = $descript2->media(0)->nodeValue; }} Quote Link to comment https://forums.phpfreaks.com/topic/18452-reading-xml-namespace-using-dom/ Share on other sites More sharing options...
448191 Posted August 23, 2006 Share Posted August 23, 2006 $xdom->getElementsByTagName("media:description");"media" is the namespace. When specified, it needs to be included. I think. I know this to be true for fetching attribute nodes, so my guess is it also aplies to element nodes.Edit for clarification:You're trying to access 'description' as it where a child element of 'media', it's not. Like I said, 'media' refers to the namespace. Quote Link to comment https://forums.phpfreaks.com/topic/18452-reading-xml-namespace-using-dom/#findComment-79363 Share on other sites More sharing options...
pkrtech Posted August 23, 2006 Author Share Posted August 23, 2006 so how do I access the value with "NAMESPACE" media:description does not work Quote Link to comment https://forums.phpfreaks.com/topic/18452-reading-xml-namespace-using-dom/#findComment-79402 Share on other sites More sharing options...
448191 Posted August 23, 2006 Share Posted August 23, 2006 [code]<?php$nodelist = $xdom->getElementsByTagName("media:description");foreach ($nodelist as $element){ echo $element->nodeValue.'<br />';}?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/18452-reading-xml-namespace-using-dom/#findComment-79410 Share on other sites More sharing options...
448191 Posted August 23, 2006 Share Posted August 23, 2006 Just noticed your modification.Try this instead:[code]<?php$nodelist = $xdom->getElementsByTagNameNS('media','description');?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/18452-reading-xml-namespace-using-dom/#findComment-79416 Share on other sites More sharing options...
pkrtech Posted August 23, 2006 Author Share Posted August 23, 2006 yea that doesnt work either tried it. Thats why Im so confused. Quote Link to comment https://forums.phpfreaks.com/topic/18452-reading-xml-namespace-using-dom/#findComment-79424 Share on other sites More sharing options...
448191 Posted August 23, 2006 Share Posted August 23, 2006 Well, getElementsByTagNameNS shouldn't work (and it doesn't dissapoint in that). getElementsByTagName('NS:TAG') should work as far as I can tell, but I can't seem to get it either. ??? Quote Link to comment https://forums.phpfreaks.com/topic/18452-reading-xml-namespace-using-dom/#findComment-79449 Share on other sites More sharing options...
pkrtech Posted August 23, 2006 Author Share Posted August 23, 2006 Yea been trying to find somewhere someone has it, it has to be possible yes ? Quote Link to comment https://forums.phpfreaks.com/topic/18452-reading-xml-namespace-using-dom/#findComment-79461 Share on other sites More sharing options...
448191 Posted August 23, 2006 Share Posted August 23, 2006 [code]<?php$xdom = new DOMDocument;$cycle = 'http://video.google.com/videofeed?type=search&q=is%3Aforsale&so=1&num=20&output=rss';$xdom->load($cycle);$items = $xdom->getElementsByTagName("item");foreach($items as $item){ $nodelist = $item->getElementsByTagName('description'); foreach ($nodelist as $element){ if($element->tagName == 'media:description'){ echo htmlspecialchars($element->nodeValue).'<br />'; } }}?>[/code]Above works. It amazes me though, why getElementsByTagName doesn't take the namespace, while the DOMElement->tagName property does include it ??? Very very strange... Quote Link to comment https://forums.phpfreaks.com/topic/18452-reading-xml-namespace-using-dom/#findComment-79463 Share on other sites More sharing options...
pkrtech Posted August 23, 2006 Author Share Posted August 23, 2006 Wow you rock! Thanks so much. You dont know what I been going through to get that. Karma is yours today my friend. Quote Link to comment https://forums.phpfreaks.com/topic/18452-reading-xml-namespace-using-dom/#findComment-79470 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.