I can't figure out or find out how to parse the permission="allowed"
value out of this xml, using PHP simplexml_load_file
.
the basic structure is
<?xml version='1.0' encoding='UTF-8'?>
<entry xmlns="http://www.w3.org/2005/Atom" xmlns:media="http://search.yahoo.com/mrss/" xmlns:gd="http://schemas.google.com/g/2005" xmlns:yt="http://gdata.youtube.com/schemas/2007" gd:etag="W/"DkEDSH47eCp7I2A9WhJbEEQ."">
<yt:accessControl action="comment" permission="allowed" />
<yt:accessControl action="commentVote" permission="allowed" />
<yt:accessControl action="videoRespond" permission="moderated" />
<yt:accessControl action="rate" permission="allowed" />
<yt:accessControl action="embed" permission="allowed" />
<yt:accessControl action="list" permission="allowed" />
<yt:accessControl action="autoPlay" permission="allowed" />
<yt:accessControl action="syndicate" permission="allowed" />
How can get to the value of the permission=allowed
attribute on that last line?
This was so annoying to figure out...
(where
$xml = simplexml_load_file($source);
)I'm able to get to the permission attribute with:
You want to use XPath to retrieve records, it's an XML query language.
Please see the SimpleXMLElement's xpath() and registerXPathNamespace() methods. W3Schools explains XPath's syntax here.
For this XML
you'd register a namespace like this: