Streaming XML feeds and simplexml load string parsing error

304 views
Skip to first unread message

Ryan Hungate

unread,
Oct 31, 2013, 12:04:43 PM10/31/13
to guz...@googlegroups.com
Im using the Guzzle PhpStreamRequestFactory to load an xml file ( dynamically generated on another server ) that occasionally runs into a hiccup when I parse the string into simplexml... the one that happens the most often is :  simplexml_load_string(): parser error : Entity 'nbsp' not defined...

I know that this is a decoding error on the stream but im wondering what Guzzle normally does on this subject to avoid the errors on parsing the XML.. there are a million comments about how to properly load the xml string into simplexml, but i am asking the pros here. :)

Michael

unread,
Oct 31, 2013, 8:25:34 PM10/31/13
to guz...@googlegroups.com
When using the PhpStreamRequestFactory, you are only getting little bits of the response body at a time. If you try to pass the data you receive from this into SimpleXML, then you will get parse errors due to the XML being incomplete.

You might need to look into a streaming XML parser like XML Parser (http://us1.php.net/manual/en/ref.xml.php) or XML Reader (http://us1.php.net/manual/en/book.xmlreader.php), though I'm not sure if XML Reader allows you to stream data into its parser.

Ryan Hungate

unread,
Oct 31, 2013, 8:31:17 PM10/31/13
to guz...@googlegroups.com
Hey Michael… actually Im letting the entire stream complete before loading the simplexml… if that makes any difference.  I had to do this because we get random huge feed problems with an API that we work with and I needed to verify the byte size to avoid the problem, which is why Im using the StreamFactory…

Thanks

Ryan

--
You received this message because you are subscribed to a topic in the Google Groups "Guzzle - PHP HTTP client and REST client framework" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/guzzle/8kDXWMDf_ec/unsubscribe.
To unsubscribe from this group and all its topics, send an email to guzzle+un...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Michael Dowling

unread,
Oct 31, 2013, 9:36:59 PM10/31/13
to guz...@googlegroups.com
Gotcha. That makes more sense, but it's strange that the xml is sometimes mangled. Let me know if you come up with anything that needs to be fixed.

Thanks,
Michael
You received this message because you are subscribed to the Google Groups "Guzzle - PHP HTTP client and REST client framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to guzzle+un...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages