读书人

linq to xml大侠们 快

发布时间: 2012-01-02 22:40:04 作者: rapoo

linq to xml大侠们 快救命啊

C# code
<?xml version='1.0' encoding='UTF-8'?><result status="ok"><order id="5141" orderNo="jpa110506120442266" allPrice="1379" status="CANCEL_OK" contact="刘畅如苑" contactMob="15910399872" contactEmail="" payStatus="0" createTime="2011-05-06 12:04:42.0" needPS="true"><flight code="CA1860" cabin="W" dep="LZH" arr="PEK" depDay="2011-05-09" depTime="15:35" arrTime="18:45" pnr="JEZ8EZ" cpnr="" realCode="" viewPrice="1180" price="1179.0" constructionFee="50" fuelTax="110" childFuelTax="60" policyType="SP"/><passenger name="刘畅如苑" ageType="0" cardType="NI" cardNum="450204198807020624" eticketNum="" insuranceCount="1" insuranceNo=""/><log operator="System" time="2011-05-06 13:07:32.0" action="将超时订单自动删除"/><log operator="彭松" time="2011-05-06 12:06:29.0" action="修改订单,将【订单状态】由【等待座位确认】修改为【订座成功等待支付】;"/><log operator="System" time="2011-05-06 12:05:11.0" action="PATA校验异常,原因:无价格,PATA为没有符合条件的运价, 请使用手工处理  b。将订单状态改为【等待座位确认】"/><log operator="System" time="2011-05-06 12:04:44.0" action="创建订单!"/></order><order id="5142" orderNo="jpa110506120442266" allPrice="1379" status="CANCEL_OK" contact="刘畅如苑" contactMob="15910399872" contactEmail="" payStatus="0" createTime="2011-05-06 12:04:42.0" needPS="true"><flight code="CA1860" cabin="W" dep="LZH" arr="PEK" depDay="2011-05-09" depTime="15:35" arrTime="18:45" pnr="JEZ8EZ" cpnr="" realCode="" viewPrice="1180" price="1179.0" constructionFee="50" fuelTax="110" childFuelTax="60" policyType="SP"/><passenger name="刘畅如苑" ageType="0" cardType="NI" cardNum="450204198807020624" eticketNum="" insuranceCount="1" insuranceNo=""/><log operator="System" time="2011-05-06 13:07:32.0" action="将超时订单自动删除"/><log operator="彭松" time="2011-05-06 12:06:29.0" action="修改订单,将【订单状态】由【等待座位确认】修改为【订座成功等待支付】;"/><log operator="System" time="2011-05-06 12:05:11.0" action="PATA校验异常,原因:无价格,PATA为没有符合条件的运价, 请使用手工处理  b。将订单状态改为【等待座位确认】"/><log operator="System" time="2011-05-06 12:04:44.0" action="创建订单!"/></order><result>

上面是我的xml文档
C# code
var info = from t in xml.Descendants("order")                       select new TTSJp8orderModel {                           //订单信息                           OrderId = t.Attribute("orderNo").Value,                           OrderState = t.Attribute("status").Value,                           OrderType = t.Element("flight").Attribute("policyType").Value,                           ReceiveWay = t.Attribute("payStatus").Value,                           Contact = t.Attribute("contact").Value,                           telephone = t.Attribute("contactMob").Value,                           Price = decimal.Parse(t.Attribute("allPrice").Value),                           OrderNo=t.Attribute("orderNo").Value,                           PayWay=t.Attribute("payStatus").Value,                           //航班信息                           PNR = t.Element("flight").Attribute("pnr").Value,                           AirFlight = t.Element("flight").Attribute("code").Value,                           GoCity = t.Element("flight").Attribute("dep").Value,                           EndCity=t.Element("flight").Attribute("arr").Value,                           Godate = t.Element("flight").Attribute("depDay").Value + t.Element("flight").Attribute("depTime").Value,                           J_Price=t.Element("flight").Attribute("constructionFee").Value,                           R_Price=t.Element("flight").Attribute("fuelTax").Value,                           Code = t.Element("flight").Attribute("cabin").Value,                           //AirName=t.Element("")                           //乘客信息                           Passager=(??)//passager是我定义的一个List<PassagerInfo>实体 一个order节点里可能有多个passager  我怎么取得这个Passager集合 啊 



[解决办法]
C# code
var info = from t in xml.Descendants("order")                       select new  TTSJp8orderModel {                           //订单信息                           OrderId = t.Attribute("orderNo").Value,                           OrderState = t.Attribute("status").Value,                           OrderType = t.Element("flight").Attribute("policyType").Value,                           ReceiveWay = t.Attribute("payStatus").Value,                           Contact = t.Attribute("contact").Value,                           telephone = t.Attribute("contactMob").Value,                           Price = decimal.Parse(t.Attribute("allPrice").Value),                           OrderNo=t.Attribute("orderNo").Value,                           PayWay=t.Attribute("payStatus").Value,                           //航班信息                           PNR = t.Element("flight").Attribute("pnr").Value,                           AirFlight = t.Element("flight").Attribute("code").Value,                           GoCity = t.Element("flight").Attribute("dep").Value,                           EndCity=t.Element("flight").Attribute("arr").Value,                           Godate = t.Element("flight").Attribute("depDay").Value + t.Element("flight").Attribute("depTime").Value,                           J_Price=t.Element("flight").Attribute("constructionFee").Value,                           R_Price=t.Element("flight").Attribute("fuelTax").Value,                           Code = t.Element("flight").Attribute("cabin").Value,                           //AirName=t.Element("")                           //乘客信息                           Passager=( from s in t.Descendants("passenger")                                     select new PassagerInfo{ name=s.Attribute("name").Value }).ToList()                        }; 

读书人网 >.NET

热点推荐