Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

Coding Forum


You are currently viewing our Coding Forum as a guest. Please register to participate.
Login



Reply
PHP SimpleXML parser error : Premature end of data in tag feed line 1
Old 07-16-2009, 09:44 AM PHP SimpleXML parser error : Premature end of data in tag feed line 1
Junior Talker

Posts: 1
Trades: 0
Hi.
I'm getting a parser error on my XML feed from YouTube's friend activity feed.
The error I am recieving is:
Quote:
Warning: SimpleXMLElement::__construct() [function.SimpleXMLElement---construct]: Entity: line 1: parser error : Premature end of data in tag feed line 1 in /media/morpheus/yasn/includes/youtube.php on line 86

Warning: SimpleXMLElement::__construct() [function.SimpleXMLElement---construct]: x>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage> in /media/morpheus/yasn/includes/youtube.php on line 86

Warning: SimpleXMLElement::__construct() [function.SimpleXMLElement---construct]: ^ in /media/morpheus/yasn/includes/youtube.php on line 86

Fatal error: Uncaught exception 'Exception' with message 'String could not be parsed as XML' in /media/morpheus/yasn/includes/youtube.php:86 Stack trace: #0 /media/morpheus/yasn/includes/youtube.php(86): SimpleXMLElement->__construct('<feed xmlns='ht...') #1 /media/morpheus/yasn/stream_test.php(70): YouTube->get_friends_activity() #2 {main} thrown in /media/morpheus/yasn/includes/youtube.php on line 86
The content of the XML feed is: (spaced out so easier to read)
HTML Code:
<feed xmlns='http://www.w3.org/2005/Atom'
xmlns:openSearch='http://a9.com/-/spec/opensearch/1.1/'
xmlns:gd='http://schemas.google.com/g/2005'
gd:etag='W/"DUQHQXs6cCp7ImA9WxJUF0k."'>
  <id>
  tag:youtube.com,2008:user:amalcontentiwilson:friendsactivity</id>
  <updated>2009-07-16T05:28:50.518-07:00</updated>
  <category scheme='http://schemas.google.com/g/2005#kind'
  term='http://gdata.youtube.com/schemas/2007#userEvent' />
  <title>Activity of the friends of amalcontentiwilson</title>
  <logo>
  http://www.youtube.com/img/pic_youtubelogo_123x63.gif</logo>
  <link rel='http://schemas.google.com/g/2005#feed'
  type='application/atom+xml'
  href='http://gdata.youtube.com/feeds/api/users/amalcontentiwilson/friendsactivity' />
  <link rel='http://schemas.google.com/g/2005#batch'
  type='application/atom+xml'
  href='http://gdata.youtube.com/feeds/api/users/amalcontentiwilson/friendsactivity/batch' />
  <link rel='self' type='application/atom+xml'
  href='http://gdata.youtube.com/feeds/api/users/amalcontentiwilson/friendsactivity?start-index=1&amp;max-results=25' />
  <link rel='service' type='application/atomsvc+xml'
  href='http://gdata.youtube.com/feeds/api/users/amalcontentiwilson/friendsactivity?alt=atom-service' />
  <author>
    <name>YouTube</name>
    <uri>http://www.youtube.com/</uri>
  </author>
  <generator version='2.0' uri='http://gdata.youtube.com/'>YouTube
  data API</generator>
  <openSearch:totalResults>0</openSearch:totalResults>
  <openSearch:startIndex>1</openSearch:startIndex>
  <openSearch:itemsPerPage>25</openSearch:itemsPerPage>
</feed>
Could someone help me to see why this is not valid and how to solve the problem?
Thanks.
adammw is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 08-10-2009, 10:42 AM Re: PHP SimpleXML parser error : Premature end of data in tag feed line 1
Junior Talker

Posts: 1
Trades: 0
I have the same problem, any ideas?
jcgeilomat is offline
Reply With Quote
View Public Profile
 
Old 08-03-2010, 01:53 PM Re: PHP SimpleXML parser error : Premature end of data in tag feed line 1
Junior Talker

Posts: 1
Name: F
Trades: 0
I had the same error and fixed it by loading DOM first, then converting to SimpleXML. Instead of just loading the XML string directly to SimpleXML. Have no idea why SimpleXML errorer on loading the google custom search results xml string.

$this->xmlDoc = file_get_contents($this->url, 0, stream_context_create(array('http' => array('timeout' => 1))) );

if(!$this->xmlDoc) $this->error = "Could not get $url";
else
{
$dom = new DOMDocument;
$dom->loadXML($this->xmlDoc);
if (!$dom)
{
echo 'Error while parsing the document';
exit;
}
$this->xmlObj = simplexml_import_dom($dom);
/*
try {
$this->xmlObj = new SimpleXMLElement($this->xmlDoc);
}
catch (Exception $e)
{
$this->error = "SimpleXML did not work";
echo $this->error; exit;
}
*/
}


Error message before the fix was:


PHP Warning: SimpleXMLElement::__construct() [<a href='simplexmlelement.--construct'>simplexmlelement.--construct</a>]: Entity: line 3: parser error : Premature end of data in tag GSP line 2 in googleCustomSearch.php on line 27

SimpleXMLElement::__construct() [<a href='simplexmlelement.--construct'>simplexmlelement.--construct</a>]: &lt;ERROR&gt;500&lt;/ERROR&gt;

PHP Warning: SimpleXMLElement::__construct() [<a href='simplexmlelement.--construct'>simplexmlelement.--construct</a>]:
flight553 is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to PHP SimpleXML parser error : Premature end of data in tag feed line 1
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.14174 seconds with 12 queries