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;
}
}
}
查看全文
相关阅读:
MFC自绘框架窗口客户区
命令行下创建mysql数据库
linux重置mysql root密码的6种方
xampp修改mysql默认密码详解
Java常用包装类
Java异常处理
Java数组
Java流程控制
Java基本数据类型
golang https server分析
原文地址:https://www.cnblogs.com/RChen/p/199938.html
最新文章
Java中的四种引用类型,强引用,软引用,弱引用,虚引用
Java中instanceof关键字的理解
webpack5编写loader时 如何使用Chrome进行调试
手写一个webpack5 loader,功能:如果less头部有对应的转换注释,那么将less文件内的所有px转换为vw
webpack 手写的loader引入报错 Module not found: Error: path argument is not a string
for(var i=0;i<5;i++){setTimeout(()=>{console.log(i)}, 0)} 的几种解法
MySQL新增用户及赋予权限
vsftpd配置详解
Linux的运行级别和设置开机启动服务的方式
Linux服务器初步配置流程
热门文章
Linux下的Locale详解
这11个足以改变生活的想法,让1000万读者为之点赞
JetBrain系列IDE提示Filesystem Case-Sensitivity Mismatch的解决
一道php笔试题
来了一波神操作,把所有文章都删了。。。
python中的矩阵、多维数组----numpy
虚拟机Ubuntu系统下kaldi安装与编译简介
安装python各类工具包、IDE以及著名开源模块如kaldi等的简单总结
初识Python、PyCharm、Anaconda与tensorflow
MFC绘图相关GDI工具对象和函数介绍
Copyright © 2011-2022 走看看