Beispiel #1
0
<?php

$csv = new SimpleTable();
$dom = DOMDocument::load('supplementalData.xml');
$csv->load_byDomAttribs($dom, "/supplementalData/languageData/language[@territories]", ['type', 'alt', 'territories'])->save('scrapped/languageData_bylang.csv');
$csv->load_byDomAttribs($dom, "/supplementalData/territoryContainment/group[not(@status)]", ['type', 'contains'])->save('scrapped/territoryContainment.csv');
$popPercMin = 1;
$csv->load_byDomFunc($dom, function ($xp, $node, $head) use($popPercMin) {
    $oficiais = [];
    $etc = [];
    $country = $node->getAttribute('type');
    $pop = $node->getAttribute('population');
    $lst = $xp->query("languagePopulation", $node);
    // subquery
    if ($lst->length) {
        foreach ($lst as $g) {
            $lang = $g->getAttribute('type');
            $popPerc = $g->getAttribute('populationPercent');
            if ($g->getAttribute('officialStatus') == 'official') {
                $oficiais[] = $lang;
            } elseif ((int) $popPerc >= $popPercMin) {
                $etc[] = $lang;
            }
        }
    }
    // if for $g
    return [$country, $pop, join(' ', $oficiais), join(' ', $etc)];
}, "/supplementalData/territoryInfo/territory", ['country', 'population', 'langs_official', 'langs_other'])->save('scrapped/territoryInfo.csv');
// testar -> joinWith($csv2, [1=>2,2=>1], [3,4]) -> save();
//country,langs_official,langs_otherGt1perc
//FALTA (inclui tag -BR, etc. da lang oficial caso exista IETF)