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;
}
}
}
查看全文
相关阅读:
docker 安装 nexus3 初始密码不再是admin123
eclipse中Tomcat修改项目名称
WAMP3.1.3自定义根目录
git学习笔记
小米和MAC触摸板手势汇总
IDEA快捷键汇总
servelet 实现Post接口访问
LeetCode:Jump Game II
LeetCode:Trapping Rain Water
LeetCode: Container With Most Water
原文地址:https://www.cnblogs.com/RChen/p/199938.html
最新文章
arrow--时间格式化方法
mysql删除重复的数据并保持唯一性
mysql删除数据后id自增不连续的解决方法
Ubuntu 解决 OSError: mysql_config not found 报错
matplotlib 中文乱码问题(服务器和本地)
python -- UTC时间转换成北京时间 和 字符串的替换
在阿里云Centos7.6上面配置Mysql主从数据库(master/slave),实现读写分离
在阿里云Centos7.6上利用docker搭建Jenkins来自动化部署Djang
在阿里云Centos7.6上面部署基于redis的分布式爬虫scrapy-redis
使用基于Vue.js和Hbuilder的混合模式移动开发打造属于自己的移动app
热门文章
vue中function无法访问到data中的例数据
vue超简选中行改变样式demo
js乘法口诀表
js双重for循环&打印星星案例
v-for遍历数组和对象
vue中v-on的使用,参数,修饰符
git常用命令行
Linux 调整系统时间偏差
Linux环境mysql快速备份及迁移
正则表达式获取字符串的input标签的属性值
Copyright © 2011-2022 走看看