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