Load full XML with simplexml_load_string

Asked

Viewed 55 times

0

I have an XML that has a parent node Produtos and 2500 knots children produto, Every child us has a key id that starts at 1 and goes up to 2500. When I try to load the XML using the function simplexml_load_string only 2237 child nodes are "parsed", is there any limit to this function? if yes how can I increase? below follows code used;

$call = curl_init();

$options = [
    CURLOPT_URL             => $import->xml_path,
    CURLOPT_RETURNTRANSFER  => 1,
    CURLOPT_SSL_VERIFYPEER  => false,
    CURLOPT_CUSTOMREQUEST   => 'GET',
    CURLOPT_CONNECTTIMEOUT  => 20,
    CURLOPT_RETURNTRANSFER  => 1,
    CURLOPT_SSL_VERIFYHOST  => 0,
];

$xml = simplexml_load_string($xmlString, null, LIBXML_NOCDATA);
// => $xml é uma classe SimpleXMLElement com um attributo `produto` (array) com 2238 indices.
  • At the end of this loaded xml, it closes the Products node or stays open ? try increasing the memory limit ini_set('memory_limit', '512M');

  • I’ve tried it and it hasn’t changed a bit @Anthraxisbr

1 answer

0

As of libxml version 2.7.3 the function simplexml_load_string can only receive up to 10MB per call.

According to:

Since version 2.7.3 libxml Limits the Maximum size of a single text Node to 10MB. The limit can be Removed with a new option, XML_PARSE_HUGE. PHP has no way to specify this option to libxml.

Can use XML_PARSE_HUGE to circumvent this limitation, since it is not possible to define libxml directly.

References:

XML_PARSE_HUGE on Function simplexml_load_string()

PHP bug report

Browser other questions tagged

You are not signed in. Login or sign up in order to post.