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;
}
}
}
查看全文
相关阅读:
ArrayList和LinkedList比较
高度最小的BST
Linux查看网络即时网速
UISegmentedControl判断点击第几项
ant关于发邮件报错535 Error:authentication failed解决方法
Selenium WebDriver下载地址
GitLab服务器IP地址修改
jenkins+gitlab自动化构建
GitLab默认密码
jenkins全局安全配置-授权策略,误操作将设置为遗留模式,导致无全部管理员权限,修改config.xml的<authorizationStrategy 为以下
原文地址:https://www.cnblogs.com/RChen/p/199938.html
最新文章
Winform消息与并行的形象比喻
C#语言struct结构体适用场景和注意事项
java.lang.ClassNotFoundException: rx.functions.Func1
不知道为什么用th:value不会显示值,用th:utext就可以!!!
Co initialization failed with java.lang.UnsatisfiedLinkError: no sapjco3 in java.library.path
shh中如何访问URL内容?
java.lang.NoClassDefFoundError: org/apache/commons/beanutils/PropertyUtils这是什么错误?
解决SVN Cleanup错误: Failed to run the WC DB work queue associated with
HTTP Status 405
奇怪的Hello World!
热门文章
控制器里无法使用@Controller和@RequestMapping等注释
jsp中EL表达式不起作用的问题
Python+Kepler.gl轻松制作酷炫路径动画
第三次理解asyncio
Java套接字编程
String中各方法多数情况下返回新的String对象
寻找面积最大的凸多边形
StringTokenizer类
Java Api系列之String方法综述(JDK1.7)
Scanner的使用
Copyright © 2011-2022 走看看