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;
}
}
}
查看全文
相关阅读:
IDEA取消自动更新
string常见面试题
IDEA不能运行main方法
GIT: Incorrect username or password
淘宝技术架构演进之路
javac编译原理之生死人肉白骨
this string "--" is not permitted within comments ,(mapper文件)注释中不能使用--
IE下input的type=file需要双击触发
解决问题思路
python
原文地址:https://www.cnblogs.com/RChen/p/199938.html
最新文章
JSFL:导入Png图片导出swf
20170524 连接数据库
20170513爬取猫眼电影Top100
20170513 Python练习册0013爬取贴吧妹子照片
20170513 Python练习册0011过滤敏感词
20170512 Python练习册0004统计英文的纯文本文件的单词出现的个数
20170511 Python练习册0000 将头像右上角加上红色的数字
20170502 匹配单个字符串
20170430python中reduce函数
20170430 math.sqrt函数
热门文章
Python 爬虫实战(一)——requests+正则表达式 爬取猫眼TOP100
python setuptools 打包工具
ubuntu 为USB串口绑定固定的设备名
收集单个脚本的step 结果和 case 的结果
python 单例模式
Git API
(三)grpc-流式传输
(二)grpc-protobuf 数据类型
SpringBoot项目登陆页面
程序包org.springframework.boot不存在
Copyright © 2011-2022 走看看