0

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

this does not work

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

thanks in adv, Richard

2
  • I can't reproduce the problem. Can you please make it a tested, self-contained example script? Commented Jan 17, 2010 at 17:30
  • hmm, how exactly, originally, I gave the output variable to the view object and disable the layout in the mvc. I can put this code on top off the indexfile instead, that way I will be sure that only this code is run. Commented Jan 17, 2010 at 17:36

3 Answers 3

3

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

Sign up to request clarification or add additional context in comments.

Comments

2

$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

3 Comments

thanks, if this is the solution Is 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?
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?
I can see the output with the header set to text/plain I consider this question closed. Thanks VolkerK. Time for me to struggle a bit further.
1

Why not just use file_put_contents ? like this

file_put_contents("myxml.xml",$xml);

1 Comment

I don't know about that one yet. I have to look into that

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.