阅读以下XML格式的最佳方式 [英] Best way to read the following XML format
问题描述
我有一个xml文件,格式如下:
I have a xml file with the following format :
<list name="a">
<person>
<field name="Name">aaa</field>
<field name="lname">bb'b'</field>
<field name="tel">123</field>
<field name="tel">1234</field>
<field name="tel">12345</field>
</person>
<person>
<field name="Name">vvv</field>
<field name="lname">fff'</field>
<field name="tel">1</field>
<field name="tel">2</field>
<field name="tel">3</field>
</person>
<person>
<field name="Name">ccc</field>
<field name="lname">bb:'c'</field>
<field name="tel">4</field>
<field name="tel">5</field>
<field name="tel">6</field>
</person>
</list>
和以下结构:
and the following struct :
struct person
{
string name;
string lname;
string[] tel;
}
我在使用以下格式读取和写入xml的不同方法之间感到困惑我尽力尝试方法T但不是我想要的结果
我想:
1-读取文件并将内容放到struct array或dataTable中显示在gridView中。
2-将dataTable或Struct写入一个与输入格式相同的文件
我尽力尝试方法,但不是我想要的结果xmlWriter也没有逃避'和'中的值,如:
bb'b'而不是bb'b'
我尝试过:
xmlserializer
xmlReader
xmlWriter
生成文本manualy
I got confused between different methods to read and write xml with following format I did my best to try methods T but not the result I wanted
I want to :
1- read the file and put the contents to struct array or dataTable to show in gridView.
2- write dataTable or Struct to a file with exacly same format as the input
I did my best to try methods , but not the result I wanted also the xmlWriter doesn't escape the ' and " in values like :
bb'b' instead of bb'b'
What I have tried:
xmlserializer
xmlReader
xmlWriter
generating text manualy
推荐答案
0)使用类而不是结构。
1)使用序列化来加载/保存xml。
0) Use a class instead of a struct.
1) Use serialization to load/save the xml.
这篇关于阅读以下XML格式的最佳方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!