0
我无法从这个XML得到以下信息命名空间:解析XML APFeeds使用PHP和SimpleXML
<apcm:Property Name="EntitlementMatch" Id="urn:publicid:ap.org:product:41664" Value="AP Top News" />
<apcm:Property Name="EntitlementMatch" Id="urn:publicid:ap.org:product:42430" Value="AP Top News - International - Stories" />
<apcm:Property Name="EntitlementMatch" Id="urn:publicid:ap.org:package:100518" Value="AP Top News Package" />
具体来说,我需要的“ID”和“价值”字段。
这里是XML的主要部分:
<?xml version="1.0" encoding="utf-8" ?>
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:apcm="http://ap.org/schemas/03/2005/apcm" xmlns:apnm="http://ap.org/schemas/03/2005/apnm" xmlns:georss="http://www.georss.org/georss" xmlns:o="http://w3.org/ns/odrl/2/">
...
<entry xmlns="http://www.w3.org/2005/Atom">
...
<apcm:ContentMetadata xmlns:apcm="http://ap.org/schemas/03/2005/apcm">
...
<apcm:Property Name="EntitlementMatch" Id="urn:publicid:ap.org:product:41664" Value="AP Top News" />
<apcm:Property Name="EntitlementMatch" Id="urn:publicid:ap.org:product:42430" Value="AP Top News - International - Stories" />
<apcm:Property Name="EntitlementMatch" Id="urn:publicid:ap.org:package:100518" Value="AP Top News Package" />
...
</apcm:ContentMetadata>
</entry>
</feed>
我一直在看下面的SO职位,以揣摩出来,而这一次是最有帮助的,到目前为止:Identical nested XML elements with namespaces and PHP
而这里的是我与打码:
$ns_dc = $feed_entry->children($ns['apcm']);
echo "APCM children: " . count($ns_dc) . "<br />";
$inner_ns_dc = $feed_entry->children($ns_dc["apcm:Property"]);
echo "APCM Property Children: " . count($inner_ns_dc) . "<br />";
//$sxe = new SimpleXMLElement($feed_entry);
$sxe = new SimpleXMLElement($feed_entry->asXML());
foreach($sxe->apcm as $item) {
printf("%s\n", $item);
}
$sxe->registerXPathNamespace('apcm', 'http://ap.org/schemas/03/2005/apcm');
$result = $sxe->xpath('/apcm:Property:*');
echo "Result count: " . count($result) . "<br />";
foreach ($result as $sequenceNumber) {
echo $sequenceNumber . "<br />";
}