Here’s my code:
XmlNodeList otherImageId =
document.DocumentElement
.SelectNodes("/OHManager/config/customimage/image/@id");
XmlNodeList otherImage =
document.DocumentElement
.SelectNodes("/OHManager/config/customimage/image");
for (int i = 0; i < 5; i++)
{
Console.WriteLine("Image Id" + otherImageId[i].InnerText.ToString());
Console.WriteLine("File name" + otherImage[i].InnerText.ToString());
}
The XML:
<OHManager>
<config type="image">
<customimage no="5">
<image id="1">Sea Wallpaper.jpg</image>
<image id="2">Sea Wallpaper.jpg</image>
<image id="3">Sea Wallpaper.jpg</image>
<image id="4">Sea Wallpaper.jpg</image>
<image id="5">Sea Wallpaper.jpg</image>
</customimage>
</config>
</OHManager>
The output:
Image Id1
File name10101010
Image Id2
File name10101010
Image Id3
File name10101010
Image Id4
File name10101010
Image Id5
Notice how there are lines File name10101010. I cannot figure out how to get the correct file name: Sea Wallpaper.jpg. It’s giving me the image id but not the file name.
You dont need to perform 2 XPath queries against your xml document, one will suffice. This code should demonstrate how to get bothe the
idattribute and the inner text of the node:Live example: http://rextester.com/rundotnet?code=THABU16531