XmlNodeList nodes1 = doc.SelectNodes(@"books/book/title");<books>
    <book>
          <title author="aa">XML</title>
    </book>
</books>
author属性的值如何用这种方法读出

解决方案 »

  1.   

    XmlNodeList nodes1 = doc.SelectNodes(@"books/book/title");
    foreach(XmlNode node in nodes1)
    {
        Console.WriteLine(node.Attributes["author"].Value);
    }
      

  2.   

    看这里的代码,
    using System;
    using System.IO;
    using System.Xml;public class Sample
    {
      public static void Main()
      {
         XmlDocument doc = new XmlDocument();
         doc.LoadXml("<book genre='novel' publicationdate='1997'> " +
                     "  <title>Pride And Prejudice</title>" +
                     "</book>");      
     
         XmlAttributeCollection attrColl = doc.DocumentElement.Attributes;     Console.WriteLine("Display all the attributes for this book...");
         for (int i=0; i < attrColl.Count; i++)
         {
            Console.WriteLine("{0} = {1}", attrColl.Item(i).Name, attrColl.Item(i).Value);
         }         
        
      }
    }