我可以撤回任何非 CDATA 字段。但不是汇总字段。我已经用尽了我所知道的一切来尝试。下面是我能得到的最接近的结果,摘要字段返回空白。如果我当然对整个文件进行 var_dump ,它确实会返回,但是我无法访问特定字段。请帮忙!谢谢!
XML 示例
<?xml version="1.0" encoding="utf-8"?>
<zatom:feed xmlns:zatom="http://www.w3.org/2005/Atom" xmlns:z4m="http://namespaces.zope.com/zc/syndication" xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-us">
<zatom:updated>2013-05-09T14:46:12Z</zatom:updated>
<zatom:title>Partner feeds</zatom:title>
<zatom:author><zatom:name>Zillow</zatom:name></zatom:author>
<zatom:id>urn:Zillow:wsls20130509:0000</zatom:id>
<zatom:entry z4m:content-type="zc.z4mcontent.story" z4m:status="published">
<zatom:updated>2013-05-09T14:46:12Z</zatom:updated>
<z4m:dateline term="Syndicated"/>
<z4m:source term="Zillow"/>
<zatom:rights>© 2013</zatom:rights>
<zatom:category scheme="http://namespaces.zope.com/zc/z4m/section" term="real_estate_news" />
<zatom:title type="text">Harnessing the Power of Online Home Searches</zatom:title>
<zatom:summary type="xhtml"><div xmlns="http://www.w3.org/1999/xhtml"><![CDATA[Harnessing the Power of Online Home Searches]]></div></zatom:summary></zatom:entry>
</zatom:feed>
PHP
$str_xml = file_get_contents('http://content.zillow.com/feeds/partners/wsls/');
$obj_xml = new SimpleXMLElement($str_xml);
foreach( $obj_xml->children('zatom', true)->entry as $entries ) {
echo (string) 'Title: ' . $entries->title . '<br />';
echo (string) 'Summary: ' . simplexml_load_string($entries->summary, null, LIBXML_NOCDATA) . "<br />\n";
}