Rick Rick - 8 months ago 40
PHP Question

SimpleXML will not parse this one URL

I am developing a plugin for WordPress to read from an XML Output which is being delivered from a cloud-based POS.

This is not about complicated programming, this is more of a debug.

The XML url is: Removed :)

And the basic, simple code is:



ini_set('display_errors', true);

$url = '--URL to the XM--L';




I have tried all the approaches. DOMDoc, CURL and SimpleXML. Everything spits out errors. The coder who made the output has been able to get it to work within their domain, but I need to debug more to find out where the error may be.

I have run into quite a series of errors depending on how I feed the XML into the script.

Fatal error: Uncaught Exception: String could not be parsed as XML in /var/www/html/test2.php:27 Stack trace: #0 /var/www/html/test2.php(27): SimpleXMLElement->__construct('http://jewelbas...', NULL, true) #1 {main} thrown in /var/www/html/test2.php on line 27

And sometimes I get these weird support errors, that I assume is coming from their host, but they cannot identify them. These support errors come no matter what server I use. They come when using

Warning: simplexml_load_string(): act the webmaster. <br><br>Your support ID is: 9641638103684613562</body></html>

Answer Source

The server requires a user agent to be set. All the standard XML APIs in PHP are based on libxml. You can set a stream context for it:

      'http' => [
          "User-Agent: Foo\r\n"

$document = new DOMDocument();
echo $document->saveXML();