ID:               41784
 Updated by:       [EMAIL PROTECTED]
 Reported By:      mistknight at gmail dot com
-Status:           Open
+Status:           Bogus
 Bug Type:         SimpleXML related
 Operating System: kubuntu feisty 7.04
 PHP Version:      5.2.3
 New Comment:

That's because SimpleXML doesn't understand Atom's way of mixing
content.  The first summary node, for example, looks like this:

<summary type='xhtml'><div xmlns='http://www.w3.org/1999/xhtml'>Last
Monday, we spent some time at the <a
href='http://www.u-tokyo.ac.jp/index_e.html'>University of Tokyo</a>,
where we talked about Ruby and so on; quite a change of pace from the
rest of the visit.</div></summary>

That means that there isn't actually any string value in the summary
node.  There is however a div node there and that div node has string
contents.  Normally you would either encode the HTML or use a CDATA
block there which is probably what you had when you refer to it working
before "with nested tags".  SimpleXML has no idea that <div> is an HTML
element and not an XML element.  How would it?

So you can get the string like this:

(string)$x->entry->summary->div

But note that inside that div element, you have an <a href> element. 
The easy way to see the structure is to just do this:

print_r($x->entry->summary);

Which gives you this:

SimpleXMLElement Object
(
    [EMAIL PROTECTED] => Array
        (
            [type] => xhtml
        )

    [div] => Last Monday, we spent some time at the , where we talked
about Ruby and so on; quite a change of pace from the rest of the
visit.
)

And print_r($x->entry->summary->div); which gives you:

SimpleXMLElement Object
(
    [a] => University of Tokyo
)

You need to apply some Atom-specific logic in order to use SimpleXML to
parse an Atom feed.  One trick would be to do:

echo $x->entry->summary->asXML();

which gives you:

<summary type="xhtml"><div xmlns="http://www.w3.org/1999/xhtml";>Last
Monday, we spent some time at the <a
href="http://www.u-tokyo.ac.jp/index_e.html";>University of Tokyo</a>,
where we talked about Ruby and so on; quite a change of pace from the
rest of the visit.</div></summary>

You may not want the summary element itself.  You could avoid it by
doing something like:

foreach($x->entry->summary->children() as $child) echo
$child->asXML();

But basically there is absolutely nothing wrong with SimpleXML here.


Previous Comments:
------------------------------------------------------------------------

[2007-06-23 00:35:35] mistknight at gmail dot com

Description:
------------
First of all I admit this was on PHP 5.2.1 and I have my PHP installed
from repository, not compiled. It would be a pain to install PHP 5.2.3

Simply retrieve this ATOM 1.0 file and load it into a simpleXML object

http://www.tbray.org/ongoing/ongoing.atom

Now try to get the <entry>'s nested <content> or <summary> tags as a
string. If you cast your object like so: (string)$obj->content or
(string)$obj->summary you will get an empty string. 

Is there ANY workaround for this that will let me retrieve the string?
I tried the docs but there's nothing about this issue. They all say
simply cast to string and I've done that on other simplexmlelement
objects without problems, even elements which had nested tags. Thanks!

Expected result:
----------------
The string located inside the <content></content> or
<summary></summary> tags.

Actual result:
--------------
Empty string.


------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=41784&edit=1

Reply via email to