在读XML文件的时候
XmlDocument xmldoc=new XmlDocument();
xmldoc.Load("c:\\aaaa.xml");
XmlReader xr=new XmlNodeReader(xmldoc);XML文件中元素的属性只有一个
<F_ATTACH1 oldName="111">aaa</F_ATTACH>
要读一个元素的属性怎么读????
在线急等...

解决方案 »

  1.   

    XmlDocument xmldoc=new XmlDocument();
    xmldoc.Load("c:\\aaaa.xml");
    XmlNode _node = xmldoc.SelectSingleNode("//F_ATTACH1[@oldName='111']");
    Console.WriteLine(_node.InnerText);得到结果:aaa
      

  2.   

    可以这样写
    string strTmp;
    XmlTextReader xmltr = new XmlTextReader(strFilePath);
    while(xmltr.Read()){
      strTmp += xmltr.GetAttributes("oldName");
    }
      

  3.   

    读元素的属性用XmlElement.GetAttributes("属性名")你可以先找到节点,可以用XmlDocument.SelectSingleNodeXmlElement xe = doc.SelectSingleNode(path) as XmlElement;
    path是你的节点所在的路径string s = xe.GetAttributes("oldName");