"Log"(ルートノード)ノードに "Log"ノードの下にあるすべてのノードを読み取る必要がある "Message"ノードが含まれているかのように、XMLで特定のノードを読み取る。条件を使用して特定のXMLノードを読むC#
注:ログノードはルートノードであり、「ログ」ノードの下に多数のノードがあります。例のため
:
<TestLogDataSet>
<Log>
<Assembly>TestCase</Assembly>
<TestMethod>Application</TestMethod>
<Status>Passed</Status>
<Trace />
</Log>
<Log>
<Assembly>TestCase</Assembly>
<TestMethod>Application</TestMethod>
<Status>Failed</Status>
<Message>
<pre><![CDATA[ Error while deleting the Project]]>
</pre>
</Message>
<Trace />
</Log>
</TestLogDataSet>
コード:
string xmlFile = File.ReadAllText(@"D:\demo.xml");
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml(xmlFile);
foreach (XmlNode lognode in xmlDoc.SelectNodes("/TestLogDataSet/Log[Message]"))
{
foreach (XmlNode node in lognode.ChildNodes)
{
string n1 = node.InnerText;
textBox1.Text = n1 + "\r\n";
}
}
あなたのコードサンプルが完全ではありません。 –
何が欠けていますか? – New