当前位置: 首页>>代码示例>>PHP>>正文


PHP path::analyzeColumn方法代码示例

本文整理汇总了PHP中path::analyzeColumn方法的典型用法代码示例。如果您正苦于以下问题:PHP path::analyzeColumn方法的具体用法?PHP path::analyzeColumn怎么用?PHP path::analyzeColumn使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在path的用法示例。


在下文中一共展示了path::analyzeColumn方法的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::analyzeColumn方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。