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