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))
);
}
}
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: my xml file
At the end, my expectation is to print "UltimateHoldingCompanyName","OrganisationName","NameElement"
Thanks
<?xml version="1.0"?> ...to make it valid XML. Also your name spacesxlmns:...aren't defined.