Rev 18 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
<?phprequire_once('php/XmlStreamer.php');require_once('php/tools.php');ini_set("memory_limit", "256M");$cnt = 0;class LabelsXmlStreamer extends XmlStreamer{public function processNode($xmlString, $elementName, $nodeIndex){global $cnt;global $fh;global $fhUrls;$xml = simplexml_load_string($xmlString, 'simple_xml_extended');if ($elementName == 'label') {++$cnt;$id = $xml->id;$name = cleanName($xml->name);$profile = $xml->profile;$contactInfo = $xml->contactinfo;$parentLabel = $xml->parentLabel;$sublabels = [];if (isset($xml->sublabels)) {foreach ($xml->sublabels->label as $n) {$sublabels[] = cleanName($n);}}if (isset($xml->urls)) {foreach ($xml->urls->url as $n) {if (!empty($n)) {fputcsv2($fhUrls, array($id, $n), ',', '"');}}}$arr = array($id,$name,$parentLabel,join(", ", $sublabels));fputcsv2($fh, $arr, ',', '"');}return true;}}$xmlfile = "./in/discogs_20190701_labels.xml.gz";$fh = fopen("out/labels.load", "w+");$fhUrls = fopen("out/labelUrls.load", "w+");$xmlstream = "compress.zlib://$xmlfile";$xmlfileSize = gzfilesize($xmlfile);$streamer = new LabelsXmlStreamer($xmlstream, $xmlfileSize, true);if ($streamer->parse()) {echo "Finished $cnt labels." . PHP_EOL;} else {echo "Couldn't find root node" . PHP_EOL;}fclose($fh);fclose($fhUrls);