【发布时间】:2016-08-04 13:11:01
【问题描述】:
我还处于 XML 文件的起点。我想用 XML 创建目录,我有这个功能:
RunCommand 是一个执行 comanda_cmd 的函数 第一,第二是字符串
private void ProcesNode(XmlNode node, string parentPath, string path, string first, string second, string BuiltUnit, string item)
{
if (!node.HasChildNodes || ((node.ChildNodes.Count == 2) && (node.FirstChild is System.Xml.XmlText)))
{
//MessageBox.Show(parentPath + "/" + node.Name);
}
else
{
foreach (XmlNode child in node.ChildNodes)
{
comanda_cmd = first + "/" + parentPath + second + "/" + parentPath + "/" + node.Name;
string status = RunCommand(comanda_cmd + "/project.pj /n");
//content = "_GEN_PROJECT/" + ProjectName + "/" + BuiltUnit + "/" + item + "/" + parentPath + "/" + node.Name + " already exist";
//MessageBox.Show(content);
//check_status(status, content);
ProcesNode(child, parentPath + "/" + node.Name, path, first, second, BuiltUnit, item);
}
}
}
我有这个 XML:
<unit>
<Unit1>
<src>
<i>
<test1>
<test_in1>
<test_in_out>
<t>
</t>
</test_in_out>
</test_in1>
</test1>
<test2>
<test_in2>
</test_in2>
</test2>
</i>
</src>
<doc>
<i>
<test1>
<test_in1>
<test_in_out>
<t>
</t>
</test_in_out>
</test_in1>
</test1>
<test2>
<test_in2>
</test_in2>
</test2>
</i>
</doc>
</Unit1>
<Unit2>
<src>
<i>
</i>
</src>
</Unit2>
</unit>
我调用 ProcesNode,它会创建目录。例如:unit/Unit1/src/i/test1/test_in1/test_in_out 但没有创建最后一个目录(在我的例子中是“t”)。
我哪里错了?为什么不创建最后一个目录?
【问题讨论】:
-
对于最低标签 (
<t>),if条件(!node.HasChildren || ...)是true,因此您无需输入创建目录的else块。 -
你是对的!感谢伟大的 Rene Vogt