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:

ini_set('display_errors', true);

function get_reader($file){
  $reader = new XMLReader;
  return $reader;

function handle_Entity(SimpleXMLElement $Entity){
    This gets called everytime an album node
    has been iterated.
    "(%d) %s - %s\

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

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

  (123456) Name1 -
  (6665) Name2 -

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:

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


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