次のような XML ファイルがあります。
<root>
<song id="1">
<name> A Whole New World </name>
<artist> Lea Salonga </artist>
</song>
<song id="2">
<name> Colors of the Wind </name>
<artist> Judy Kuhn </artist>
</song>
<song id="3">
<name> Reflection </name>
<artist> Lea Salonga </artist>
</song>
<song id="4">
<name> Part of Your World </name>
<artist> Sierra Boggess </artist>
</song>
</root>
そして、この XML ファイルを C# で解析したいと考えています。System.Xml.XmlDocument
XML ファイルの解析に使用する必要があることはわかっています。Microsoft のドキュメントによると、角かっこ演算子[Name]
は「指定された最初の子要素」のみを返しますName
。
ここで私の質問は次 のとおりです。上記の XML ファイルの例から、ID 4 を持つ曲の名前を取得するにはどうすればよいですか?