本文整理汇总了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));
}