當前位置: 首頁>>代碼示例>>PHP>>正文


PHP path::analyzeBranch方法代碼示例

本文整理匯總了PHP中path::analyzeBranch方法的典型用法代碼示例。如果您正苦於以下問題:PHP path::analyzeBranch方法的具體用法?PHP path::analyzeBranch怎麽用?PHP path::analyzeBranch使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在path的用法示例。


在下文中一共展示了path::analyzeBranch方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: xml2csv

function xml2csv($xml_content)
{
    $xml = new XMLReader();
    $xml->XML($xml_content);
    //First pass - discover all path and branch points
    $cols = array();
    $root = new path(null, "root");
    $current = $root;
    while ($xml->read()) {
        if (in_array($xml->nodeType, array(XMLReader::TEXT, XMLReader::CDATA, XMLReader::WHITESPACE, XMLReader::SIGNIFICANT_WHITESPACE))) {
            if (trim($xml->value) == "") {
                continue;
            }
            $current->hastext = true;
        }
        if ($xml->nodeType == XMLReader::ELEMENT) {
            $child = $current->findChild($xml->name);
            if ($child !== null) {
                $current = $child;
                $current->counter++;
            } else {
                //brand new path
                $current = new path($current, $xml->name);
            }
        }
        if ($xml->nodeType == XMLReader::END_ELEMENT) {
            $current->analyzeBranch();
            $current = $current->parent;
        }
    }
    //output column headder
    $cols = array();
    $root->analyzeColumn($cols);
    foreach ($cols as $path) {
        //append parent's path name to be more descriptive
        if ($path->parent !== null) {
            echo $path->parent->name . "/";
        }
        echo $path->name;
        echo ",";
    }
    echo "\n";
    //Second pass - map values to current branch points
    $xml->XML($xml_content);
    $current = $root;
    $branch = null;
    while ($xml->read()) {
        if (in_array($xml->nodeType, array(XMLReader::TEXT, XMLReader::CDATA, XMLReader::WHITESPACE, XMLReader::SIGNIFICANT_WHITESPACE))) {
            $value = trim($xml->value);
            if (trim($xml->value) == "") {
                continue;
            }
            $branch->row[$current->colid] = $value;
        }
        if ($xml->nodeType == XMLReader::ELEMENT) {
            $current = $current->findChild($xml->name);
            $branch = $current->getBranch();
        }
        if ($xml->nodeType == XMLReader::END_ELEMENT) {
            if ($current == $branch) {
                $branch->closeBranch();
            }
            $current = $current->parent;
            $branch_new = $current->getBranch();
            if ($branch_new !== null) {
                $branch = $branch_new;
            }
        }
    }
    //dump the content
    $root->output(sizeof($cols));
}
開發者ID:wangfeilong321,項目名稱:myosg,代碼行數:72,代碼來源:xml2csv.php


注:本文中的path::analyzeBranch方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。