【发布时间】:2014-07-09 13:05:14
【问题描述】:
我有这个 xml 文件并想使用 PHP 从中获取 d:DescriptionNL 字段,但我似乎无法找到获取它的方法。我已经得到了标题、摘要,并得到了$entry->content->{'m:properties'} 这给了我一个对象作为回报。
这里有人知道这是正确的方法还是我完全走错了路?
谢谢!
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<feed xml:base="http://website.com" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns="http://www.w3.org/2005/Atom">
<title type="text">DigestedCatalogItems</title>
<id>http://website.com</id>
<updated>2014-07-09T12:55:29Z</updated>
<link rel="self" title="DigestedCatalogItems" href="DigestedCatalogItems" />
<entry>
<id>http://website.com</id>
<title type="text">Item Title</title>
<summary type="html"></summary>
<updated>2014-07-09T12:55:29Z</updated>
<author>
<name>Item</name>
</author>
<contributor>
<uri>http://website.com</uri>
</contributor>
<link rel="edit" title="DigestedCatalogItems" href="DigestedCatalogItems('Car%20Plan')" />
<category term="IBP.Catalog.Web.DigestedCatalogItems" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" />
<content type="application/xml">
<m:properties>
<d:DescriptionNL>Item description</d:DescriptionNL>
<d:origin>Company</d:origin>
</m:properties>
</content>
</entry>
</feed>
这是我目前的 PHP 代码:
$response_xml_data = file_get_contents("http://website.com");
$data = simplexml_load_string($response_xml_data);
$array = $data->entry;
foreach($array as $row) {
//This get's me an stdClass object which I'm unable to explore any further
echo $row->content->{'m:properties'};
echo $row->author->name.' <br> ' . $row->content . '<br> <a target="_blank" href="'.$row->contributor->uri.'">'.$row->title.'</a>';
echo '<br><br>';
}
【问题讨论】:
-
请显示您目前使用的代码,以及输出