Reputation: 5962
I am using simple xml for php and trying to parse the <content>
element that is a part of following tree:
<entry>
...<title>
...<link>
...<summary>
...<content>
The problem is that <content>
element cannot be read as a string because it has "non string" content that is not wrapped in CDATA:
<content type="xhtml" xml:lang="en-US" xml:base="...">
<div xmlns="http://www.w3.org/1999/xhtml"><p><strong>text... text...</strong> text <a href="..."
target="_self">LINK</a>. text</p>
</content>
I use the following code:
$xml = simplexml_load_file($feed_uri);
and then:
foreach($xml->entry as $entry){
$item = new RSSItem();
$item->title = (string) $entry->title;
$item->content = (string)$entry->content;
$item->date = (string) $entry->published;
My content member var is empty. The others are as expected If I change $item->content = (string)$entry->content; to $item->content = $entry->content; then I get another object nested in $item->content variable
Any ide how to force parser not to interpret elements found in content element (div, p etc.) as nested elements?
Thanks in advance, L
Upvotes: 2
Views: 170
Reputation: 31078
Try $entry->content->asXML()
.
See http://php.net/simplexmlelement.asxml
Upvotes: 2