gpt4 book ai didi

php - 如何获取的xml属性?

转载 作者:行者123 更新时间:2023-12-03 05:51:44 26 4
gpt4 key购买 nike

我无法找出或找出如何使用PHP permission="allowed"从此xml解析simplexml_load_file值。

基本结构是

<?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/&quot;DkEDSH47eCp7I2A9WhJbEEQ.&quot;">
<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" />

如何获得最后一行上 permission=allowed属性的值?

最佳答案

您想使用 XPath 来检索记录,这是一种XML查询语言。

请参阅SimpleXMLElement's xpath()registerXPathNamespace()方法。
W3Schools解释XPath's syntax here

对于此XML

$xml = <<<EOD
<book xmlns:chap="http://example.org/chapter-title">
<title>My Book</title>
</book>
EOD;

您将注册一个这样的 namespace :
$sxe = new SimpleXMLElement($xml);
$sxe->registerXPathNamespace('c', 'http://example.org/chapter-title');
$result = $sxe->xpath('//c:title');

关于php - 如何获取<yt:accesscontrol>的xml属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12504612/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com