日期:2014-05-20  浏览次数:20830 次

linq to xml读取某一个节点数量
XML code
<result status="ok">
 <order id="18465" orderNo="jpa110804091637266" allPrice="3020" status="TICKET_OK" contact="刘亚平" contactMob="13910651859" contactEmail="" payStatus="13" createTime="2011-08-04 09:16:37.0" needPS="true">
  <flight code="CA1478" cabin="W" dep="KHG" arr="PEK" depDay="2011-08-30" depTime="18:00" arrTime="00:15" pnr="JRFW8Z" cpnr="" realCode="" viewPrice="2800" price="2800.0" constructionFee="50" fuelTax="150" childFuelTax="80" policyType="SP" /> 
  <passenger name="刘亚平" ageType="0" cardType="NI" cardNum="110102195209080440" eticketNum="999-2155928322" insuranceCount="1" insuranceNo="D004140651" /> 
  <log operator="蔡仁明" time="2011-08-04 11:27:08.0" action="点开了订单详情页" /> 
 </order>
</result>

这是我的xml 我想读取这个xml里flight节点数量,怎么写?

------解决方案--------------------
var data=XElement.Parse(yourxml);
 
var query=(from x in data.Descendants("flight")
select x).Count();