这是.xml中的内容
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- ArenaPackage - ArenaPanel -->
<string name="ql5l3sgiojb59-n10_ojb5" mz="txt_des">叕说明</string>
<!-- ArenaPackage - canjiaBtn -->
<string name="ql5l3sgipzlco-n3_bl1b" mz="n3">开始游戏</string>
<!-- ArenaPackage - ChakanpaimingPanel -->
<string name="ql5l3sgix1kg1e-n20_i6io" mz="txt_title">查看分数</string>
</resources>


    public static void FindXmlAndReadyToRead()
{
try
{
List<String> fileNames = new List<string>(); String Path = ".\\Xml";
DirectoryInfo folder = new DirectoryInfo(Path);
//找到当前路径下,所有包含.xml格式的文件的名字
for (int i = 0; i < folder.GetFiles("*.xml").Count(); ++i)
{
fileNames.Add(folder.GetFiles("*.xml")[i].Name);
} if (fileNames.Count <= 0)
{
Console.WriteLine("Xml文件夹下无xml文件");
return;
} foreach (String fileName in fileNames)
{
Console.WriteLine(fileName);
String filePath = Path + "\\" + fileName;
ReadXml(filePath);
}
//字典排序,通过key.length的大小,从大到小排序
dict = dict.OrderByDescending(o => o.Key.Length).ToDictionary(o => o.Key, p => p.Value); }
catch (Exception e)
{
Console.WriteLine("当前目录无Xml文件夹(需要将.xml文件放在Xml文件夹下):" + e.ToString());
}
}

  

     //读取xml中包含中文的,去重,去掉包含叕    
  public static void ReadXml(String Path)

  {
XmlDocument document = new XmlDocument();
document.Load(Path);
XmlNode xn = document.SelectSingleNode("resources");
XmlNodeList xnl = xn.ChildNodes; List<String> lists = new List<string>(); foreach (XmlNode xnode in xnl)
{
String line = xnode.InnerText; //不包含叕
int ignore = line.IndexOf("叕");
if (ignore <= -1)
{
//提取中文
Regex regex = new Regex("[\u4e00-\u9fa5]+");
MatchCollection mc = regex.Matches(line);
if (mc.Count > 0 && !dict.ContainsKey(line))
{
//将所有包含中文的字符串都放在字典里
               //所有读出去的xml包含中文的内容都在dict的key里,之后可以通过遍历dict的key写入到文本

dict.Add(line, "1");
}
}
} }

  

C# 读取Xml文件中的中文的更多相关文章

  1. 读取xml文件中的配置参数实例_java - JAVA

    文章来源:嗨学网 敏而好学论坛www.piaodoo.com 欢迎大家相互学习 paras.xml文件 <?xml version="1.0" encoding=" ...

  2. python读取xml文件中的坐标点

    用labelImg工具制作好xml文件后,需要读取其中img路径和坐标点,生成一个label.txt <annotation> <folder>big</folder&g ...

  3. .net中读取xml文件中节点的所有属性信息

    功能描述: 将数据以xml的格式记录成配置文件,需要获取配置文件中的数据时,则获取对应的配置文件,读取配置文件里对应节点的所有属性. 逻辑实现: 1.将数据配置好在xml文件中. 2.获取xml文件中 ...

  4. 读取xml文件中节点

    /// <summary> /// /// </summary> /// <param name="xmlpath">节点路径</para ...

  5. Android - 读取XML文件中的数据

    读取XML中存储的数据.将xmlfile.xml存放在assets文件夹中.在activity_main.xml中创建一个textview,用来显示读取到的数据. XML文件内容如下:xmlfile. ...

  6. python中用ElementTree.iterparse()读取xml文件中的多层节点

    我在使用Python解析比较大型的xml文件时,为了提高效率,决定使用iterparse()方法,但是发现根据网上的例子:每次if event == 'end':之后elem.clear()或者是每次 ...

  7. 在C#程序中,创建、写入、读取XML文件的方法

    一.在C#程序中,创建.写入.读取XML文件的方法 1.创建和读取XML文件的方法,Values为需要写入的值 private void WriteXML(string Values) { //保存的 ...

  8. C#程序中:如何修改xml文件中的节点(数据)

    要想在web等程序中实现动态的数据内容给新(如网页中的Flash),不会更新xml文件中的节点(数据)是远远不够的,今天在这里说一个简单的xml文件的更新,方法比较基础,很适合初学者看的,保证一看就懂 ...

  9. C#中常用的几种读取XML文件的方法

    1.C#中常用的几种读取XML文件的方法:http://blog.csdn.net/tiemufeng1122/article/details/6723764/

  10. 在C#中创建和读取XML文件

    1.创建简单的XML文件 为了便于测试,我们首先创建控制台应用程序,项目命名为CreateXml,Program.cs代码如下: 这样会在C盘根目录下创建data2.xml文件,文件内容为 using ...

随机推荐

  1. nodejs mongoose连接mongodb报错,command find requires authentication

    MongoError: command find requires authentication at Connection.<anonymous> (/home/Map/node_mod ...

  2. Cygwin64静默安装办法

    下载地址: http://www.cygwin.com/setup-x86_64.exe 静默安装办法: .\setup-x86_64.exe --no-shortcuts --root D:\\Cy ...

  3. You are using pip version 8.1.2, however version 23.0 is available.You should consider upgrading via the 'pip install --upgrade pip' command.

    今天使用python2安装es模块时报错: 原因是pip(模块管理工具)版本过低,需先升级pip,再进行安装 先替换pip的镜像,默认镜像拉取慢,还可能会失败 cd ~;mkdir .pip;touc ...

  4. kali安装CloudKeyKiller-一款阿里云AK泄露工具

    工具下载地址:https://github.com/UzJu/CloudKeyKiller 问题描述:ModuleNotFoundError: No module named 'aliyunsdkec ...

  5. MATLAB基础—基础认识

    数建-MATLAB(基础认识) 一些基本使用 clear all :清除Workspace中的所有变量 clc: 清除Command Window中的所有命令 注释:%%(空空格)多行注释 或 % 单 ...

  6. QT4.8.6移植

    sudo apt-get install libx11-dev libxext-dev libxtst-dev 配置: ./configure --prefix=/opt/qt4.8.6 -opens ...

  7. MySQL半一致读实验

    参考资料: https://dev.mysql.com/doc/refman/8.0/en/innodb-transaction-isolation-levels.html https://www.y ...

  8. 控制台程序console输入参数 获取参数

    class Program    {        static void Main(string[] args)        {                                 i ...

  9. 浅谈JS中的element.style和window.getComputedStyle()的区别

    MDN对于element.style的解释 被高光的句子中的inline style属性是指css内联样式,即元素的style属性的属性值 总结一下,element.style只能获取到元素的styl ...

  10. Linux的stat命令结果说明

    There are 3 kind of "timestamps": Access - the last time the file was read Modify - the la ...