Tuesday, 13 August 2013

How do you obtain the content of a specific node using XmlDocument in C#?

How do you obtain the content of a specific node using XmlDocument in C#?

I have an XML file that looks like:
<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>
And I want to parse this XML file with C#. I know that I should use
System.Xml.XmlDocument to parse the XML file. The Microsoft documentation
says the square bracket operator [Name] returns only "the first child
element with the specified Name".
So my question here is: how do I get, from the example XML file above, the
name of the song that has the id 4?

No comments:

Post a Comment