【发布时间】:2011-09-07 15:30:14
【问题描述】:
当节点在集合中时,有没有办法获取节点的内部文本 目前我有这个
Collection<string> DependentNodes = new Collection<string>();
foreach (XmlNode node in nodes)
{
for (int i = 0; i < node.ChildNodes.Count; i++)
{
DependentNodes.Add(node.ChildNodes[i].InnerXml);
//the reason i'm using InnerXml is that it will return all the child node of testfixture in one single line,then we can find the category & check if there's dependson
}
}
string selectedtestcase = "abc_somewords";
foreach (string s in DependentNodes)
{
if(s.Contains(selectedtestcase))
{
MessageBox.Show("aaa");
}
}
当我调试字符串 s 或索引中有这个时[在一行中]
<testfixture name="1" description="a">
<categories>
<category>abc_somewords</category>
</categories>
<test name="a" description="a">
<dependencies>
<dependson typename="dependsonthis" />
</dependencies>
</test>
</testfixture>
我想要做的是,当我们到达“testfixture 1”时,它会找到“abc_somewords”并搜索“dependson typename”节点(如果有)并获得“typename”(即“dependonthis”)。
【问题讨论】:
-
DependentNodes是什么类型? -
从属节点是一个集合
-
抱歉之前没用过Linq,怎么用?
-
如果 linq 不是你的选择,你可以试试@Jason 的回答。
-
我现在更新了我的答案以匹配新的 xml 数据,并确保仅在类别与您的文本匹配的地方提取 typename 属性的值。
标签: c# winforms collections innertext