0

Like xml_parse() (see xml_parse No memory error PHP ) the function xml_parse_into_struct() seems to have memory troubles.

Parsing an XML file (size over 9MB) gives me the error 'No memory' on the last line, last char.

$report_errors = true;

$parser = xml_parser_create('UTF-8');
xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 0);

xml_parse_into_struct($parser, $data, $vals);

if ($report_errors) {
    $errorcode = xml_get_error_code($parser);
    echo xml_error_string($errorcode) . ' line ' .
        xml_get_current_line_number($parser) . ' column ' .
        xml_get_current_column_number($parser) . PHP_EOL;
    // No memory line 3876 column 8
}
xml_parser_free($parser);

When I do not ask for errors, everything is fine: (But I do not trust it)

$report_errors = false;

Is there a way to implement chunk loading (as in link mentioned above) with xml_parse_into_struct()?

( Debian 9.5 amd64, PHP 7.0.30, libxml2 2.9.4 )

4
  • Not sure if it will cope with the files your reading, but have you tried using the SimpleXML library instead? stackoverflow.com/questions/8775669/… may help. Commented Aug 28, 2018 at 14:58
  • I believe you can find your answer here stackoverflow.com/questions/19152613/… Commented Aug 28, 2018 at 15:17
  • @unixmiah this is the same link as I wrote in my first line. As I understood xml_parse_into_struct() this function needs to see the whole XML string, not only a chunk at a time. Commented Aug 30, 2018 at 6:06
  • @nigelRen do you know of any replacement of xml_parse_into_struct() with SimpleXML? (this is only a small part of a bigger project and I cannot rewrite all of their code) Commented Aug 30, 2018 at 6:36

0

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.