加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
genDotFile.php 1.59 KB
一键复制 编辑 原始数据 按行查看 历史
m 提交于 2017-09-11 17:56 . t.v
<?php
function make1node_lable($nd, $f) {
static $gtmp = 0;
$str = $nd->nodeName . $gtmp . " [\n";
$gtmp += 1;
$str .= " label = \"{" . $nd->nodeName . "\n";
$str .= " |+ name : string" . "\n";
$str .= " \\l+ age : int\n";
$str .= " \\l|+ die() : void\\l\n";
$str .= " }\"";
$str .= "]\n\n";
fwrite($f, $str);
}
function make_dot_file_title($f) {
$str = "digraph graphname {\n";
$str .= " nodesep=2.5;\n";
$str .= " node [shape = record];\n";
fwrite($f, $str);
}
function gen_dot_file($gccxml_path) {
if (!file_exists($gccxml_path)) {
print($gccxml_path . " do not exists.");
return;
}
$xmlDoc = new DOMDocument();
$xmlDoc->load($gccxml_path);
$x = $xmlDoc->documentElement;
$dotfile = fopen($gccxml_path . ".dot", "w") or die("Unable to open file!" . $gccxml_path . ".dot");
make_dot_file_title($dotfile);
foreach ($x->childNodes AS $item) {
if(!isset($item->nodeName)) {
continue;
}
if('#text' == $item->nodeName) {
continue;
}
//print "<tagName>:" . $item->nodeName . "\n";
make1node_lable($item, $dotfile);
foreach($item->attributes as $b) {
//echo " <attr>:" . $b->nodeName . ":" . $b->nodeValue . "\n";
}
foreach($item->childNodes as $ic) {
if(!isset($ic->nodeName)) {
continue;
}
if('#text' == $ic->nodeName) {
continue;
}
//print " <childTag>:" . $ic->nodeName . "\n";
foreach($ic->attributes as $ica) {
//echo " <attr>:" . $ica->nodeName . ":" . $ica->nodeValue . "\n";
}
}
}
fwrite($dotfile, "}\n");
fclose($dotfile);
}
//gen_dot_file("upload/demo.xml");
?>
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化