views:

306

answers:

3

Hi,

Does anybody know how I can get this xml into the domDocument?

Right now, it throws an error saying it is missing a top level element. What I see is that feed is the toplevel element, so it's a mystery to me. This only happens if I run it threw the domDocument and not when I echo it out directly. The xml validator also gives no errors.

This is the xml:

$xml="<?xml version='1.0' encoding='UTF-8'?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:gphoto='http://schemas.google.com/photos/2007' xmlns:openSearch='http://a9.com/-/spec/opensearch/1.1/' xmlns:gd='http://schemas.google.com/g/2005' gd:etag='W/&quot;CEANSXg7cSp7ImA9WxBRGUU.&quot;'><id>http://picasaweb.google.com/data/feed/user/rich3607/albumid/5424469095880909921&lt;/id&gt;&lt;updated&gt;2010-01-08T20:33:18.609Z&lt;/updated&gt;&lt;category scheme='http://schemas.google.com/g/2005#kind' term='http://schemas.google.com/photos/2007#album'/&gt;&lt;title&gt;tsa_ch&lt;/title&gt;&lt;subtitle&gt;chauffeurs&lt;/subtitle&gt;&lt;rights&gt;private&lt;/rights&gt;&lt;icon&gt;http://lh6.ggpht.com/_Q3ykLtTspk4/S0eV5xMQ5GE/AAAAAAAAAIY/req43lh-f4I/s160-c/Tsa_ch.jpg&lt;/icon&gt;&lt;link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://picasaweb.google.com/data/feed/api/user/rich3607/albumid/5424469095880909921?authkey=Gv1sRgCMvZ79uI6Z__ZQ'/&gt;&lt;link rel='alternate' type='text/html' href='http://picasaweb.google.com/rich3607/Tsa_ch?authkey=Gv1sRgCMvZ79uI6Z__ZQ'/&gt;&lt;link rel='http://schemas.google.com/photos/2007#slideshow' type='application/x-shockwave-flash' href='http://picasaweb.google.com/s/c/bin/slideshow.swf?host=picasaweb.google.com&amp;amp;RGB=0x000000&amp;amp;feed=http%3A%2F%2Fpicasaweb.google.com%2Fdata%2Ffeed%2Fapi%2Fuser%2Frich3607%2Falbumid%2F5424469095880909921%3Fauthkey%3DGv1sRgCMvZ79uI6Z__ZQ%26alt%3Drss'/&gt;&lt;link rel='http://schemas.google.com/photos/2007#report' type='text/html' href='http://picasaweb.google.com/lh/reportAbuse?uname=rich3607&amp;amp;aid=5424469095880909921'/&gt;&lt;link rel='http://schemas.google.com/acl/2007#accessControlList' type='application/atom+xml' href='http://picasaweb.google.com/data/feed/api/user/rich3607/albumid/5424469095880909921/acl?authkey=Gv1sRgCMvZ79uI6Z__ZQ'/&gt;&lt;link rel='self' type='application/atom+xml' href='http://picasaweb.google.com/data/feed/api/user/rich3607/albumid/5424469095880909921?start-index=1&amp;amp;max-results=500&amp;amp;kind=tag'/&gt;&lt;author&gt;&lt;name&gt;rich&lt;/name&gt;&lt;uri&gt;http://picasaweb.google.com/rich3607&lt;/uri&gt;&lt;/author&gt;&lt;generator version='1.00' uri='http://picasaweb.google.com/'&gt;Picasaweb&lt;/generator&gt;&lt;openSearch:totalResults&gt;4&lt;/openSearch:totalResults&gt;&lt;openSearch:startIndex&gt;1&lt;/openSearch:startIndex&gt;&lt;openSearch:itemsPerPage&gt;500&lt;/openSearch:itemsPerPage&gt;&lt;gphoto:id&gt;5424469095880909921&lt;/gphoto:id&gt;&lt;gphoto:location/&gt;&lt;gphoto:access&gt;private&lt;/gphoto:access&gt;&lt;gphoto:timestamp&gt;1262937600000&lt;/gphoto:timestamp&gt;&lt;gphoto:numphotos&gt;2&lt;/gphoto:numphotos&gt;&lt;gphoto:numphotosremaining&gt;998&lt;/gphoto:numphotosremaining&gt;&lt;gphoto:bytesUsed&gt;5866&lt;/gphoto:bytesUsed&gt;&lt;gphoto:user&gt;rich3607&lt;/gphoto:user&gt;&lt;gphoto:nickname&gt;rich&lt;/gphoto:nickname&gt;&lt;gphoto:allowPrints&gt;true&lt;/gphoto:allowPrints&gt;&lt;gphoto:allowDownloads&gt;true&lt;/gphoto:allowDownloads&gt;&lt;entry gd:etag='W/&quot;CEANSXg7cSp7ImA9WxBRGUU.&quot;'><id>http://picasaweb.google.com/data/entry/user/rich3607/albumid/5424469095880909921/tag/smarty&lt;/id&gt;&lt;updated&gt;2010-01-08T20:33:18.609Z&lt;/updated&gt;&lt;category scheme='http://schemas.google.com/g/2005#kind' term='http://schemas.google.com/photos/2007#tag'/&gt;&lt;title&gt;smarty&lt;/title&gt;&lt;summary&gt;smarty&lt;/summary&gt;&lt;link rel='alternate' type='text/html' href='http://picasaweb.google.com/lh/searchbrowse?q=smarty&amp;amp;psc=G&amp;amp;uname=rich3607&amp;amp;filter=0'/&gt;&lt;link rel='self' type='application/atom+xml' href='http://picasaweb.google.com/data/entry/api/user/rich3607/albumid/5424469095880909921/tag/smarty?authkey=Gv1sRgCMvZ79uI6Z__ZQ'/&gt;&lt;author&gt;&lt;name&gt;rich&lt;/name&gt;&lt;uri&gt;http://picasaweb.google.com/rich3607&lt;/uri&gt;&lt;/author&gt;&lt;/entry&gt;&lt;entry gd:etag='W/&quot;CEANSXg7cSp7ImA9WxBRGUU.&quot;'><id>http://picasaweb.google.com/data/entry/user/rich3607/albumid/5424469095880909921/tag/00tx343&lt;/id&gt;&lt;updated&gt;2010-01-08T20:33:18.609Z&lt;/updated&gt;&lt;category scheme='http://schemas.google.com/g/2005#kind' term='http://schemas.google.com/photos/2007#tag'/&gt;&lt;title&gt;00tx343&lt;/title&gt;&lt;summary&gt;00tx343&lt;/summary&gt;&lt;link rel='alternate' type='text/html' href='http://picasaweb.google.com/lh/searchbrowse?q=00tx343&amp;amp;psc=G&amp;amp;uname=rich3607&amp;amp;filter=0'/&gt;&lt;link rel='self' type='application/atom+xml' href='http://picasaweb.google.com/data/entry/api/user/rich3607/albumid/5424469095880909921/tag/00tx343?authkey=Gv1sRgCMvZ79uI6Z__ZQ'/&gt;&lt;author&gt;&lt;name&gt;rich&lt;/name&gt;&lt;uri&gt;http://picasaweb.google.com/rich3607&lt;/uri&gt;&lt;/author&gt;&lt;/entry&gt;&lt;entry gd:etag='W/&quot;CEANSXg7cSp7ImA9WxBRGUU.&quot;'><id>http://picasaweb.google.com/data/entry/user/rich3607/albumid/5424469095880909921/tag/xpl-amsterdam&lt;/id&gt;&lt;updated&gt;2010-01-08T20:33:18.609Z&lt;/updated&gt;&lt;category scheme='http://schemas.google.com/g/2005#kind' term='http://schemas.google.com/photos/2007#tag'/&gt;&lt;title&gt;xpl-amsterdam&lt;/title&gt;&lt;summary&gt;xpl-amsterdam&lt;/summary&gt;&lt;link rel='alternate' type='text/html' href='http://picasaweb.google.com/lh/searchbrowse?q=xpl-amsterdam&amp;amp;psc=G&amp;amp;uname=rich3607&amp;amp;filter=0'/&gt;&lt;link rel='self' type='application/atom+xml' href='http://picasaweb.google.com/data/entry/api/user/rich3607/albumid/5424469095880909921/tag/xpl-amsterdam?authkey=Gv1sRgCMvZ79uI6Z__ZQ'/&gt;&lt;author&gt;&lt;name&gt;rich&lt;/name&gt;&lt;uri&gt;http://picasaweb.google.com/rich3607&lt;/uri&gt;&lt;/author&gt;&lt;gphoto:weight&gt;2&lt;/gphoto:weight&gt;&lt;/entry&gt;&lt;entry gd:etag='W/&quot;CEANSXg7cSp7ImA9WxBRGUU.&quot;'><id>http://picasaweb.google.com/data/entry/user/rich3607/albumid/5424469095880909921/tag/stupid&lt;/id&gt;&lt;updated&gt;2010-01-08T20:33:18.609Z&lt;/updated&gt;&lt;category scheme='http://schemas.google.com/g/2005#kind' term='http://schemas.google.com/photos/2007#tag'/&gt;&lt;title&gt;stupid&lt;/title&gt;&lt;summary&gt;stupid&lt;/summary&gt;&lt;link rel='alternate' type='text/html' href='http://picasaweb.google.com/lh/searchbrowse?q=stupid&amp;amp;psc=G&amp;amp;uname=rich3607&amp;amp;filter=0'/&gt;&lt;link rel='self' type='application/atom+xml' href='http://picasaweb.google.com/data/entry/api/user/rich3607/albumid/5424469095880909921/tag/stupid?authkey=Gv1sRgCMvZ79uI6Z__ZQ'/&gt;&lt;author&gt;&lt;name&gt;rich&lt;/name&gt;&lt;uri&gt;http://picasaweb.google.com/rich3607&lt;/uri&gt;&lt;/author&gt;&lt;/entry&gt;&lt;/feed&gt;";

this does not work

@$dom = new DOMDocument();      
$dom_xml = $dom->loadXML($xml); 
$output= $dom_xml->saveXML(); 
echo $output;

thanks in adv, Richard

+3  A: 

The best way to load from a string is to use the loadXML function.

Kibbee
thanks, but it won't work for me
Richard
+2  A: 

$dom->loadXML($xml); doesn't return an object when called in an object context (i.e. $obj->loadxml()) but modifies the internal state of the object itself.

e.g.

$doc = new DOMDocument();      
$doc->loadXML($xml) or die('loadxml failed');
$output= $doc->saveXML(); 
echo phpversion(), "\n";
echo '|savexml|=', strlen($output), "\n";
echo '|children| = ', $doc->documentElement->childNodes->length, "\n";

prints (on my machine)

5.3.1
|savexml|=5840
|children| = 33
VolkerK
thanks, if this is the solutionIs it not possible then to echo the output again and see the rss feed page. All I get is an error with the top level el missing?
Richard
actually, I can see the same output as you. IE was caching, so I opend another browser window. Thanks for helping me out. I only have this question left. If I run it threw the domDocument without making alterations. Can I get the same xml back, because if I set a header to xml. The output will cause errors?
Richard
I can see the output with the header set to text/plainI consider this question closed. Thanks VolkerK. Time for me to struggle a bit further.
Richard
+1  A: 

Why not just use file_put_contents ? like this

file_put_contents("myxml.xml",$xml);
streetparade
I don't know about that one yet. I have to look into that
Richard