我有这个功能
private void ProcesNode(XmlNode node, string parentPath, string path, string first, string second, string BuiltUnit, string item, dynamic queries )
{
if (!node.HasChildNodes || ((node.ChildNodes.Count == 2) && (node.FirstChild is System.Xml.XmlText)))
{
comanda_cmd = first + "/" + parentPath + second + "/" + parentPath + "/" + node.Attributes["Name"].Value;
//string status = RunCommand(comanda_cmd + "/project.pj /n");
}
else
{
foreach (XmlNode child in node.ChildNodes)
{
comanda_cmd = first + "/" + parentPath + second + "/" + parentPath + "/" + node.Attributes["Name"].Value;
//with parenthPath and node.Attributes["Name"].Value create a new comanda_cnmd
//string status = RunCommand(comanda_cmd + "/project.pj /n");//this will execute comanda_cmd
// when i arrive at the third child i want to do something
//the second child attribute can be the same with the third child attribute
foreach (var ele in queries)
if (node.Attributes["Name"].Value == ele)
{
status = RunCommand(comanda1 + "/" + ele + comanda2 + "/" + ele + "/src/project.pj /n");
status = RunCommand(comanda1 + "/" + ele + comanda2 + "/" + ele + "/doc/project.pj /n");
status = RunCommand(comanda1 + "/" + ele + comanda2 + "/" + ele + "/tst/project.pj /n");
}
ProcesNode(child, parentPath + "/" + node.Attributes["Name"].Value, path, first, second, BuiltUnit, item, queries);
}
}
}
当我运行这个函数时,我遍历xml中的每个节点,并实现由parentPath和node.Attributes [“Name”]组成的CMD的订单。值。当我到达第三个孩子时,我想做点什么。我怎么知道节点是第三个? 这是XML
<unit>
<Dir Name="rte">
<Dir Name="rte">
<Dir Name="src" />
</Dir>
<Dir Name="rte_cdd">
<Dir Name="src" />
</Dir>
<Dir Name="rte_ecal">
<Dir Name="src" />
</Dir>
<Dir Name="rte_serv">
<Dir Name="src" />
</Dir>
</Dir>
</unit>
我尝试使用下面的代码创建三级所有节点的列表,但是当第二个子属性(“rte”)与第三个子属性(“rte”)相等时,执行if并且命令是为第二个孩子执行。
var tst = XElement.Load(build_units_xmls[el]);
var thirdLevelChildren = tst
.Elements("Dir")
.Elements("Dir")
.Attributes("Name")
.Select(f => f.Value);
我该怎么办?