c# 读取xml 某个节点值

一、xml格式如下:

<?xml version="1.0" encoding="UTF-8"?>
<Freight>
<freight Area="河南" ExpreName="圆通">
<FreYkg>1000</FreYkg>
<FreYkgPrice>800</FreYkgPrice>
<FreAkg>2000</FreAkg>
<FreAkgPrice>200</FreAkgPrice>
</freight>
<freight Area="河北" ExpreName="圆通">
<FreYkg>1000</FreYkg>
<FreYkgPrice>800</FreYkgPrice>
<FreAkg>2000</FreAkg>
<FreAkgPrice>200</FreAkgPrice>
</freight>
</Freight>

想要获取的内容是:Area="河北"  下某节点值,应该怎么读取

XmlDocument doc = new XmlDocument();
string path = Server.MapPath("../Xml/EMS.xml");
doc.Load(path);
XmlNode node = doc.SelectSingleNode("Freight/freight[@Area='河北']|Freight/freight[@ExpreName='圆通']");/*查询的条件Area='河北' 或者 ExpreName='圆通'*/

if(node!=null)

{

  string basePrice = node.SelectSingleNode("FreYkg").InnerText;

  string price = node.SelectSingleNode("FreYkgPrice").InnerText;

}

 

posted @ 2018-05-16 10:43  xxm_0122  阅读(1042)  评论(0编辑  收藏  举报