|
After a bit more research, here is another way to write the SearchForArtist() method. You'll notice that it does not use XPathNavigator directly, however it achieves the same result as my original code and is, I think, a little clearer to read.
public void SearchForArtist(string artist) {
XmlNode root = document.DocumentElement;
XmlNodeList nodeList = root.SelectNodes("//CD[@artist=normalize-space('" + artist + "')]");
Console.WriteLine("CDs by {0}:", artist);
foreach (XmlElement cd in nodeList) {
Console.WriteLine(" \"{0}\"", cd.GetAttribute("title"));
}
}
|