电脑故障

位置:IT落伍者 >> 电脑故障 >> 浏览文章

用LINQ做成的RSS查看器


发布日期:2020/12/27
 

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();

}

上一篇:如何获取子进程的输出

下一篇:winfrom让弹出的MessageBox在指定时间内销毁