zoukankan
html css js c++ java
读取XML文件内容的简单方法
读取XML文件内容的简单方法:
/**/
///
<summary>
///
XmlOperation 的摘要说明。
///
</summary>
public
sealed
class
XmlOperation
{
//
private static string configFile = System.IO.Path.GetFullPath("..\\..\\Xml\\Words.xml");
private
static
string
configFile
=
System.IO.Path.GetFullPath(
"
Xml\\Words.xml
"
);
/**/
///
<summary>
///
获取字符拼音名称
///
</summary>
///
<param name="database">
汉字
</param>
///
<returns>
真实库名
</returns>
public
static
string
GetWordPYName(
string
word)
{
XmlDocument xml
=
new
XmlDocument();
try
{
xml.Load(configFile);
XmlElement root
=
xml.DocumentElement;
string
xpath
=
"
descendant::word[@cname='
"
+
word
+
"
']
"
;
XmlNode dbNode
=
root.SelectSingleNode(xpath);
string
pyName
=
""
;
if
(dbNode
!=
null
)
{
pyName
=
dbNode.Attributes[
"
pyname
"
].Value;
}
else
{
pyName
=
word;
}
return
pyName;
}
catch
(Exception ex)
{
return
word;
}
}
}
下面是对应的XML文件:
<?
xml version
=
"
1.0
"
encoding
=
"
utf-8
"
?>
<
words
>
<
word cname
=
"
单
"
pyname
=
"
shan
"
/>
<
word cname
=
"
朴
"
pyname
=
"
piao
"
/>
<
word cname
=
"
石
"
pyname
=
"
shi
"
/>
<
word cname
=
"
乐
"
pyname
=
"
yue
"
/>
<
word cname
=
"
召
"
pyname
=
"
shao
"
/>
<
word cname
=
"
贲
"
pyname
=
"
ben
"
/>
<
word cname
=
"
隗
"
pyname
=
"
kui
"
/>
<
word cname
=
"
区
"
pyname
=
"
ou
"
/>
<
word cname
=
"
长
"
pyname
=
"
zhang
"
/>
<
word cname
=
"
仇
"
pyname
=
"
qiu
"
/>
<
word cname
=
"
喘
"
pyname
=
"
xie
"
/>
<
word cname
=
"
尉
"
pyname
=
"
yi
"
/>
</
words
>
查看全文
相关阅读:
QDUOJ LC的课后辅导 单调递增栈
蓝桥杯 时间问题
区间sum 和为k的连续区间-前缀和
康托展开-全排列的编码与解码
康托展开-全排列应用
背包之01背包、完全背包、多重背包详解
HDU
辗转相除求最大公约数与最小公倍数
快速幂(反复平方法)
HDU
原文地址:https://www.cnblogs.com/adam/p/698018.html
最新文章
MySQL:BlackHole
如何最快地实现 ALTER TABLE
How to Read an Engineering Research Paper
Small things are better
Working with large data sets in MySQL
Why MySQL could be slow with large tables ?
android学习2——RelativeLayout
android学习1——LinearLayout
groovy学习(五) 命令行输入输出
groovy学习(四)io
热门文章
groovy学习(三)range
groovy学习(二)map
groovy学习(一)列表
java split函数应该注意的问题
重构改善既有代码的设计(笔记)
idea常用设置
QDUOJ 一道简单的数据结构题 栈的使用(括号配对)
POJ
yzm10铺瓷砖 一只小蜜蜂 ycb与取款机
HDU
Copyright © 2011-2022 走看看