XML CDATA not returning properly with simplexml_load_string() nor SimpleXMLElement() (PHP) -


i can pull of non-cdata fields. not summary field. i've exhausted know try. below close get, summary field returning blank. return if var_dump of whole file of course, can't access specific fields. please help! thanks!

xml sample

<?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>&#169; 2013</zatom:rights> <zatom:category scheme="http://namespaces.zope.com/zc/z4m/section" term="real_estate_news" /> <zatom:title type="text">harnessing power of online home searches</zatom:title> <zatom:summary type="xhtml"><div xmlns="http://www.w3.org/1999/xhtml"><![cdata[harnessing 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 $entries ) {         echo (string) 'title: ' . $entries->title . '<br />';             echo (string) 'summary: ' . simplexml_load_string($entries->summary, null, libxml_nocdata) . "<br />\n";     } 

you have minor problem in code, simplexml_load_string documentation refers:

takes well-formed xml string , returns object.

and you're providing simplexmlelement first argument. replace line code one:

echo (string) 'summary: ' . simplexml_load_string($entries->summary->children()->asxml(), null, libxml_nocdata) . "<br />\n"; 

Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -