熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> .NET編程 >> 正文

用LINQ做成的RSS查看器

2013-11-13 09:47:50  來源: .NET編程 

  private void btnSubmit_Click(object sender EventArgs e)

  {

  GetRss();

  }

  private void txtUrl_KeyDown(object sender KeyEventArgs e)

  {

  if (eKeyCode == KeysEnter)

  {

  GetRss();

  }

  }

  private void GetRss()

  {

  try

  {

  XElement doc = XElementLoad(txtUrlText LoadOptionsNone);

  //使用LINQ檢索所有的節點

  var els = from el in docElements()

  select el;

  appendtree(els tvdomNodes null);

  }

  catch (Exception ex)

  {

  MessageBoxShow(exMessage 加載出錯);

  }

  }

  /**//// <summary>

  /// 把XML節點上的值顯示在TreeView上

  /// </summary>

  /// <param name=els></param>

  /// <param name=tnc></param>

  /// <param name=tnel></param>

  private void appendtree(IEnumerable<XElement> els TreeNodeCollection tnc XElement tnel)

  {

  tncClear();

  if (elsCount<XElement>() == && tnel != null)

  {

  tncAdd(new TreeNode(tnelValue));

  return;

  }

  foreach (var el in els)

  {

  TreeNode tn = new TreeNode(elNameLocalName new TreeNode[] { new TreeNode(StringEmpty) });

  tnTag = el;

  tncAdd(tn);

  }

  }

  private void tvdom_AfterExpand(object sender TreeViewEventArgs e)

  {

  if (eNode != null)

  {

  XElement tnel = eNodeTag as XElement;

  if (tnel != null)

  {

  //利用LINQ查詢節點

  var els = from el in tnelElements()

  select el;

  appendtree(els eNodeNodes tnel);

  }

  }

  }

  private void tvdom_AfterSelect(object sender TreeViewEventArgs e)

  {

  eNodeExpand();

  }


From:http://tw.wingwit.com/Article/program/net/201311/11609.html
    推薦文章
    Copyright © 2005-2013 電腦知識網 Computer Knowledge   All rights reserved.