-1

I am trying to parse XML of size 140mb with simplexml_load_file() like this

$sxe = simplexml_load_file("file.xml"); 
print_r($sxe);

it only return the object

SimpleXMLElement Object
(
    [@attributes] => Array
        (
            [version] => 2.12
            [vocab-version] => 2015-09-08-01
        )

)

but the same code works on server. I have tried everything, increasing memory limit, uploaded size etc but didn't get any success. And the same code works for some small xml files.

halfer
  • 19,824
  • 17
  • 99
  • 186
Atul Saini
  • 61
  • 1
  • 7
  • could you please provide any more information? for example the *code* we are supposed to debug? – Franz Gleichmann Oct 26 '16 at 09:35
  • sure,iam using this $sxe = simplexml_load_file("file.xml"); print_r($sxe); – Atul Saini Oct 26 '16 at 09:36
  • **don't** post code in comments. **edit** your original post instead. – Franz Gleichmann Oct 26 '16 at 09:37
  • and as i suppose it should return the object with all the attribute from the xml, but it only return version (as i mention above) – Atul Saini Oct 26 '16 at 09:38
  • You can combine XMLReader with SimpleXML: http://stackoverflow.com/questions/24084203/replacing-parsing-function-with-xmlreader-in-specific-php-code/24084918#24084918 This way only a part of the XML will be loaded into memory. – ThW Oct 26 '16 at 09:42
  • my xml has a different structure ,it is not suitable for the example listed http://stackoverflow.com/questions/24084203/replacing-parsing-function-with-xmlreader-in-specific-php-code/24084918#24084918 – Atul Saini Oct 26 '16 at 10:02

1 Answers1

0
$simplexml = simplexml_load_file($file_path, 'SimpleXMLElement', LIBXML_PARSEHUGE|LIBXML_NSCLEAN);
//OR
$simplexml = new SimpleXMLElement($xml_string, LIBXML_PARSEHUGE|LIBXML_NSCLEAN);

Can you run this code like this example?

madankundu
  • 154
  • 8
  • Please try search in google with LIBXML_PARSEHUGE|LIBXML_NSCLEAN you can see lot of max size file solution, – madankundu Oct 26 '16 at 10:18
  • $xsl->loadXML(file_get_contents('xml_path'), LIBXML_PARSEHUGE);iam able to parse by this but actually i want the object of simple xml element,can you help me in coverting the dom document object to simple xml – Atul Saini Oct 27 '16 at 05:45