日期:2014-05-16  浏览次数:20808 次

怎么读取XML里面的属性啊?
额,以前没有用过XML,现在有用到求帮忙。
<result>
  <row gmcode="050" martprice="80.176" bid="80.176" ask="80.176" change="0.008" minprice="80.123" maxprice="80.188" bidtime="2014/3/5 15:45:10"  price="80.176" pricestart="80.171" priceclose="80.168000" />
  <row gmcode="023" martprice="21.18" bid="21.2" ask="21.16" change="-0.04" minprice="21.15" maxprice="21.28" bidtime="2014/3/5 15:45:10"  price="21.18" pricestart="21.21" priceclose="21.220000" />
  <row gmcode="00E" martprice="103.275" bid="103.27" ask="103.28" change="0.04" minprice="103.175" maxprice="103.525" bidtime="2014/3/5 15:45:12"  price="103.275" pricestart="103.255" priceclose="103.235000" />
  <row gmcode="022" martprice="1333.96" bid="1334.21" ask="1333.71" change="-2.79" minprice="1333.07" maxprice="1338.12" bidtime="2014/3/5 15:45:14"  price="1333.96" pricestart="1336.67" priceclose="1336.750000" />
</result>


额,就是读取里面属性的值。
------解决方案--------------------
使用XmlDocument类
http://support.microsoft.com/kb/301101/zh-cn
------解决方案--------------------

XmlDocument doc = new XmlDocument();
doc.Load(path);//从指定的路径加载Xml文件 
XmlNode xn = doc.SelectSingleNode("result");
XmlNodeList xnList = xn.ChildNodes; 
forech(XmlNode xl in xnList)
{
 XmlElement xe = (XmlElement)xl;
 string str = xe.GetAttribute("bid").ToString();
}

------解决方案--------------------
http://blog.csdn.net/happy09li/article/details/7460521
------解决方案--------------------
可以参考这个例子http://blog.csdn.net/jiankunking/article/details/17992679