zoukankan
html css js c++ java
Get ancestors list in an XML document
using
System;
using
System.Collections;
using
System.ComponentModel;
using
System.Drawing;
using
System.Windows.Forms;
using
System.Xml;
namespace
ReadXmlDemo
{
/**/
///
<summary>
///
Form1 的摘要说明。
///
</summary>
public
class
Form1 : Form
{
private
Button button1;
private
Container components
=
null
;
public
static
void
Main()
{
Application.Run(
new
Form1());
}
public
Form1()
{
InitializeComponent();
}
protected
override
void
Dispose(
bool
disposing)
{
if
(disposing)
{
if
(components
!=
null
)
{
components.Dispose();
}
}
base
.Dispose(disposing);
}
Windows 窗体设计器生成的代码
#region
Windows 窗体设计器生成的代码
/**/
///
<summary>
///
设计器支持所需的方法 - 不要使用代码编辑器修改
///
此方法的内容。
///
</summary>
private
void
InitializeComponent()
{
this
.button1
=
new
Button();
this
.SuspendLayout();
//
//
button1
//
this
.button1.Location
=
new
Point(
176
,
48
);
this
.button1.Name
=
"
button1
"
;
this
.button1.TabIndex
=
0
;
this
.button1.Text
=
"
button1
"
;
this
.button1.Click
+=
new
EventHandler(
this
.button1_Click);
//
//
Form1
//
this
.AutoScaleBaseSize
=
new
Size(
6
,
14
);
this
.ClientSize
=
new
Size(
292
,
273
);
this
.Controls.Add(
this
.button1);
this
.Name
=
"
Form1
"
;
this
.Text
=
"
Form1
"
;
this
.ResumeLayout(
false
);
}
#endregion
private
void
button1_Click(
object
sender, EventArgs e)
{
Setup();
string
url
=
"
/pmanager/scm/frmscmindex.aspx
"
;
string
param
=
"
projectid
"
;
XmlNode[] ancestors
=
GetAncestorNodeList(url, param);
//
test results
if
(ancestors
!=
null
)
{
foreach
(XmlNode node
in
ancestors)
MessageBox.Show(node.OuterXml);
}
}
private
XmlDocument doc;
/**/
///
<summary>
///
加载 Xml 文档
///
</summary>
private
void
Setup()
{
doc
=
new
XmlDocument();
try
{
doc.Load(Application.StartupPath
+
"
\\nav.xml
"
);
}
catch
{
throw
new
Exception(
"
Xml 文件加载失败。
"
);
}
}
/**/
///
<summary>
///
得到指定节点的祖先节点的数组(强类型)
///
</summary>
///
<param name="url"></param>
///
<param name="param"></param>
///
<returns></returns>
private
XmlNode[] GetAncestorNodeList(
string
url,
string
param)
{
XmlNode targetNode
=
doc.SelectSingleNode(
"
//siteMapNode[@url='
"
+
url
+
"
' and @param='
"
+
param
+
"
']
"
);
if
(targetNode
==
null
)
return
null
;
ArrayList alAncestors
=
new
ArrayList();
for
(XmlNode node
=
targetNode.ParentNode;
node
!=
null
&&
node
!=
doc.DocumentElement;
node
=
node.ParentNode)
{
alAncestors.Add(node);
}
alAncestors.Reverse();
XmlNode[] nodeList
=
(XmlNode[]) alAncestors.ToArray(
typeof
(XmlNode));
return
nodeList;
}
}
}
查看全文
相关阅读:
Codeforces Round #502 (in memory of Leopoldo Taravilse, Div. 1 + Div. 2) E. The Supersonic Rocket
Codeforces Round #500 (Div. 2) D
AtCoder Grand Contest 026 D
Codeforces Round #495 (Div. 2) Sonya and Matrix
AtCoder Regular Contest 100 E
1013 数素数
1010 一元多项式求导(用while接收输入)
1009 说反话(字符串、栈)
L2-006 树的遍历 (后序中序求层序)
L2-004 这是二叉搜索树吗?
原文地址:https://www.cnblogs.com/RChen/p/199938.html
最新文章
使用 Docker Compose 部署 MySQL+Tomcat
Docker 常用命令汇总
基于 Ubuntu 安装 Docker
Spring Boot 整合 Shiro 实现登录认证与权限控制
Spring Boot 中使用 TKMybatis 和 PageHelper
Matlab实现《追光者》简谱
傅里叶级数的可视化
王者荣耀刷金币小程序
仿今日头条横向滚动导航栏--原生js
选项卡--原生js
热门文章
MySQL基本语法
一道面试题(C语言)
PHP 生成验证码(+图片没有显示的解决办法)
由百度 “PHP薪资” 引发的思考
PHP进行数据库操作时遇到的一个问题
Codeforces Round #504 (rated, Div. 1 + Div. 2, based on VK Cup 2018 Final) D. Array Restoration
AtCoder Regular Contest 101 D
2018 ACM-ICPC World Finals
Codeforces Round #503 (by SIS, Div. 2) D. The hat
Codeforces Round #503 (by SIS, Div. 2) C. Elections
Copyright © 2011-2022 走看看