【发布时间】:2018-05-16 04:49:55
【问题描述】:
我有一个如下所示的 xml 文件
<ExecutionGraph>
<If uniqKey="1">
<Do>
<If uniqKey="6">
<Do />
<Else />
</If>
</Do>
<Else>
<If uniqKey="2">
<Do />
<Else>
<If uniqKey="3">
<Do />
<Else />
</If>
</Else>
</If>
</Else>
</If>
</ExecutionGraph>
现在我想找到 uniqKey=3 并插入
<Task id="3" xmlns="urn:workflow-schema">
<Parent id="-1" />
</Task>
进入其<Do> 标签。
我尝试的是下面的 c# 代码。
var element = xGraph
.Descendants()
.Where(x => (string)x.Attribute("uniqKey") == parent.Key.ToString()).first();
现在elemenet 有整个标签,但我无法将我的任务插入到它的<DO> 孩子中。
所需的输出:
<ExecutionGraph>
<If uniqKey="1">
<Do>
<If uniqKey="6">
<Do />
<Else />
</If>
</Do>
<Else>
<If uniqKey="2">
<Do />
<Else>
<If uniqKey="3">
<Do>
<Task id="3"
xmlns="urn:workflow-schema">
<Parent id="-1" />
</Task>
</Do>
<Else />
</If>
</Else>
</If>
</Else>
</If>
提前致谢。
【问题讨论】: