为什么我在读取xml时节点没有setattribute和getattribute的属性,
只有根节点有呢?纳闷

解决方案 »

  1.   

    直接这样取,或者赋值
    string text = XmlNode.Attribute["name"].Value;
    XmlNode.Attribute["name"].Value = "new value";
      

  2.   

    我是这样做的但是抱错总说null,感觉好像attribute只能读
        If Not Me.IsPostBack Then
                Dim myxmldocument As New XmlDocument
                myxmldocument.Load(Server.MapPath("XMLFile1.xml)
                Dim x As XmlNodeList
                Dim i As Integer
                x = myxmldocument.GetElementsByTagName("book")
                For i = 0 To x.Count - 1
                    x.Item(i).Attributes("aa").Value = "bb"---就抱错了
                Next
      

  3.   

    ((XmlElement)XmlDoc.SelectNodes("EVI/FlatExcelSchema/Item")[0]).GetAttribute("topCell"); 供参考
      

  4.   

    给null设置当然出错,查查msdn.  XmlAttributeCollection.Append
      

  5.   

    if (oNode.Attributes.GetNamedItem("readonly") != null)
                {
                    _TrReadOnly = oNode.Attributes.GetNamedItem("readonly").Value.ToString();
    }
      

  6.   

    如果没有属性,先创建一个再加到节点上
    XmlAttribute xmlAtt= xmlDoc.CreateAttribute("name");
    xmlAtt.Value = "";
    xmlnode.Attributes.Append(xmlAtt);