基于条件的xml linq消息框

时间:2016-09-20 11:22:04

标签: c# xml linq if-statement

基于此xml

  <Reservation>
  <SeatEconomy>2</SeatEconomy>
  <SeatFirst>14</SeatFirst> 
  </Reservation>

如何根据特定条件显示MessageBox?即伪代码:

  //case 1 Economy Class
   if(elementName==SeatEconomy) 
   MessageBox.Show(string.Format("Economy class assigned seat {0}",   
   name6.ToString()), "Results", MessageBoxButtons.YesNoCancel);

  //case 2 First Class
  if(elementName==SeatFirst) 
   MessageBox.Show(string.Format("First class assigned seat {0}",   
   name6.ToString()), "Results", MessageBoxButtons.YesNoCancel);

到目前为止我所做的事情:

    XDocument info = XDocument.Load("reservation.xml");
    var result = from reservat in info.Descendants("Reservation")
                     let ep = reservat.Element("SeatEconomy")
                     select ep;
        var compare = result.FirstOrDefault();

    //how can I select SeatFirst and do comparison between SeatFirst 
      and SeatEconomy?    

提前致谢。

0 个答案:

没有答案