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;
}
c# 讀取xml 某個節點值