因为做  windows CE 开发 ,想做个类似于 configuration 类来读取配置文件,用xmlreader 来读取节点和属性,
但现在只会读取节点,请问怎么读取属性。

解决方案 »

  1.   

    以下示例使用 AttributeCount 属性读取某个元素的所有属性。// Display all attributes.
    if (reader.HasAttributes) {
      Console.WriteLine("Attributes of <" + reader.Name + ">");
      for (int i = 0; i < reader.AttributeCount; i++) {
        Console.WriteLine("  {0}", reader[i]);
      }
      // Move the reader back to the element node.
      reader.MoveToElement(); 
    }以下示例在 While 循环中使用 MoveToNextAttribute 属性读取某个元素的所有属性
    if (reader.HasAttributes) {
      Console.WriteLine("Attributes of <" + reader.Name + ">");
      while (reader.MoveToNextAttribute()) {
        Console.WriteLine(" {0}={1}", reader.Name, reader.Value);
      }
      // Move the reader back to the element node.
      reader.MoveToElement();
    }
      

  2.   

    以下示例按名称获取属性的值。
    reader.ReadToFollowing("book");
    string isbn = reader.GetAttribute("ISBN");
    Console.WriteLine("The ISBN value: " + isbn);
      

  3.   

    using (XmlReader reader = XmlReader.Create(xmlFilePath))
    {
    while (tr.Read()){
    if (tr.NodeType == XmlNodeType.Element){
      for (int i = 0; i < tr.AttributeCount; i++){
        richTextBox1.AppendText(tr.GetAttribute(i)+"\r\n");
        }
      }
    }
      

  4.   

    using (XmlReader reader = XmlReader.Create(xmlFilePath)) 

    while (reader .Read()){ 
    if (reader.NodeType == XmlNodeType.Element){ 
      for (int i = 0; i < reader.AttributeCount; i++){ 
        str+=reader.GetAttribute(i)+"\r\n"); 
        } 
      } 

      

  5.   

                XmlDocument doc = new XmlDocument();            doc.Load(url);            XmlNodeList list = doc.GetElementsByTagName("item");            XmlElement xe = (XmlElement)list[zb];            xe.GetElementsByTagName("pubDate")[0].InnerText;
      

  6.   

    大家能不能提供在 WINDOWS CE 中运行的最佳方法啊
      

  7.   

    reader 和 dom 是两套 xml 访问体系,你搞混了先看看区别?