Parsing a large (about 10 GB) nested XML file using PHP

I am new to php, and I have close to 10GB xml file to import to mysql database. The xml file is heavily nested. What I intend to extract is some information, and not to import the whole xml file. When I ran my php code, the result was blank. My php code is this:

<?php
error_reporting(-1);
ini_set('display_errors', true);

function get_reader($file){
  $reader = new XMLReader;
  $reader->open($file);
  return $reader;
}

function handle_Entity(SimpleXMLElement $Entity){
  /*
    This gets called everytime an album node
    has been iterated.
  */
  printf(
    "(%d) %s - %s\
",
    $album->N2,
    $album->N5,
    $album->N9
  );
}

$xml = get_reader('companies_xml_extract_20170703_1.xml');

while($xml->read()){
  $isNewAlbum = 'NameElement' === $xml->name && $xml->nodeType === XMLReader::ELEMENT;
  if($isNewAlbum){
    $doc = new DOMDocument('1.0', 'UTF-8');
    handle_Entity(
      simplexml_import_dom($doc->importNode($xml->expand(), true))
    );
  }
}

/*
  (123456) Name1 - http://www.site.com/url1
  (6665) Name2 - http://www.site.com/2url1
*/

From the dummy file, paths to this info are:
OrganisationName = N8:EntityList/N8:Entity/N2:OrganisationName/N2:NameElement
CompanyID = N8:EntityList/N8:Entity/N5:Identifiers/N5:Identifier/N5:IdentifierElement
UltimateHoldingCompanyName = N8:EntityList/N8:Entity/N9:UltimateHoldingCompany/N2:OrganisationName/N2:NameElement

Find attached the dummy xml file:
https://drive.google.com/file/d/0B0MjygvBH6bsSTRUZUZQam5teW8/view?usp=sharing

At the end, my expectation is to print “UltimateHoldingCompanyName”,“OrganisationName”,“NameElement”

Thanks

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.