xml文件内容如下:
<?xml version="1.0"?>
<air>
  <airnew id="         1" barcode="00000100" yqmc="X射线衍射仪" code="07030105" type="y-500型" item1="30KV" item2="9904" item21="B" username="王洪顺" item3="110205" unit="X射线衍射实验室" item4=" " item5="453199" item6="5" item7="0" item8="  " item9="" item10=" " item11="00" />
  <airnew id="         2" barcode="00000200" yqmc="X射线发生器" code="07030105" type="XXQ-2005" item1="管电压200KV 管电流5mA" item2="9686" item21="B" username="王洪顺" item3="110205" unit="X射线衍射实验室" item4=" " item5="453199" item6="5" item7="0" item8="  " item9="" item10=" " item11="00" />




</air>
想根据属性barcode的值,来得到属性yqmc的值,如何做到

解决方案 »

  1.   

    string strGetValue =string.Empty;
    XmlNode xmlNode =xmlDoc.SelectSingleNode("air/airnew");  
    while(xmlNode != null)

     //未确定属性是否存在情况下最好做如下判断
    //if(xmlNode.Attributes["barcode"] !=null)
    if(xmlNode.Attributes["barcode"].Value =="00000200")
    strGetValue=xmlNode.Attributes["yqmc"].Value;
    xmlNode =xmlNode.NextSibling; 

    }
      

  2.   

    回楼上
    xmlNode =xmlNode.NextSibling; 
    这句话好像没起到想要的效果。
    每次循环都是id=1的属性
      

  3.   

    那是因为他的这句话
    if(xmlNode.Attributes["barcode"].Value =="00000200")
    你把这个值换成变量啊,用来存放你的值
      

  4.   

    抱歉上面的看错了,代码没问题。
    如果不用SelectSingleNode,这个函数能实现吗?
    我是在wince下开发,不能使用这个函数。
      

  5.   

    如果不用SelectSingleNode,这个函数能实现吗?
    我是在wince下开发,不能使用这个函数。