xmlドキュメントから特定の値を抽出しようとしています。以下の例では、「c」ノードと「d」ノードに格納されている値をリストに格納しますが、「b」ノードに「c」と「d」の両方が含まれている場合のみです。これまでのコードはすべての「b」ノードをループしますが、whileループに何を入れるか、またはこれが最善のアプローチであるかどうかはわかりません。
XmlDocument attrsXML = new XmlDocument();
attrsXML.LoadXml(dbReader["SampleXml"].ToString());
XPathNavigator nav = attrsXML.CreateNavigator();
XPathNodeIterator attribNodes = nav.Select("/a/b");
while (attribNodes.MoveNext())
{
// What do I need to put here in order to extract the 'c' and 'd' nodes?
// Any other nodes can be ignored (such as 'e' above). I am only interested
// when 'b' contains both 'c' AND 'd'.
}
データベースからロードされた「SampleXml」は次のとおりです。
<a>
<b>
<c>Extract this</c>
<d>And this</d>
<e>not this</e>
</b>
<b>
<c>not this</c>
<e>not this</e>
</b>
<b>
<c>Extract this</c>
<d>And this</d>
</b>
</a>
助けていただければ幸いです。