使用c#处理xml文件最简单的方法是什么?

时间:2022-09-21 14:07:36

I'm developing a windows app using C#. I chose xml for data storage.

我正在开发一个使用c#的windows应用程序。我选择xml作为数据存储。

It is required to read xml file, make small changes, and then write it back to hard disk.

它需要读取xml文件,进行小的更改,然后将其写回硬盘。

Now, what is the easiest way of doing this?

现在,最简单的方法是什么?

thanks in advanced!

由于先进的!

6 个解决方案

#1


0  

XLinq is much comfortable than the ordinary Xml, because is much more object oriented, supports linq, has lots of implicit casts and serializes to the standard ISO format.

XLinq比普通Xml舒服得多,因为它更面向对象,支持linq,有很多隐式类型转换,并序列化为标准的ISO格式。

#2


0  

The best way is to use XML Serialization where it loads the XML into a class (with various classes representing all the elements/attributes). You can then change the values in code and then serialize back to XML.

最好的方法是使用XML序列化,将XML加载到类中(不同的类表示所有的元素/属性)。然后,您可以更改代码中的值,然后将其序列化为XML。

To create the classes, the best thing to do is to use xsd.exe which will generate the c# classes for you from an existing XML document.

要创建类,最好的方法是使用xsd。exe,它将从现有的XML文档中为您生成c#类。

#3


0  

I think the easiest way of doing it - it is using XmlDocument class:

我认为最简单的方法是使用XmlDocument类:

var doc = new XmlDocument();
doc.Load("filename or stream or streamwriter or XmlReader");
//do something
doc.Save("filename or stream or streamwriter or XmlWriter");

#4


-1  

try look here:

试着看这里:

Best way to read write XML file in C#

用c#读取写XML文件的最佳方式

other examples here:

其他的例子:

Reading and Writing XML in C#

用c#读写XML

#5


-2  

You can use LINQ to read XML Files as described here...

您可以使用LINQ读取这里描述的XML文件……

LINQ to read XML

LINQ to XML读

#6


-2  

Check out linq to XML

查看linq到XML

#1


0  

XLinq is much comfortable than the ordinary Xml, because is much more object oriented, supports linq, has lots of implicit casts and serializes to the standard ISO format.

XLinq比普通Xml舒服得多,因为它更面向对象,支持linq,有很多隐式类型转换,并序列化为标准的ISO格式。

#2


0  

The best way is to use XML Serialization where it loads the XML into a class (with various classes representing all the elements/attributes). You can then change the values in code and then serialize back to XML.

最好的方法是使用XML序列化,将XML加载到类中(不同的类表示所有的元素/属性)。然后,您可以更改代码中的值,然后将其序列化为XML。

To create the classes, the best thing to do is to use xsd.exe which will generate the c# classes for you from an existing XML document.

要创建类,最好的方法是使用xsd。exe,它将从现有的XML文档中为您生成c#类。

#3


0  

I think the easiest way of doing it - it is using XmlDocument class:

我认为最简单的方法是使用XmlDocument类:

var doc = new XmlDocument();
doc.Load("filename or stream or streamwriter or XmlReader");
//do something
doc.Save("filename or stream or streamwriter or XmlWriter");

#4


-1  

try look here:

试着看这里:

Best way to read write XML file in C#

用c#读取写XML文件的最佳方式

other examples here:

其他的例子:

Reading and Writing XML in C#

用c#读写XML

#5


-2  

You can use LINQ to read XML Files as described here...

您可以使用LINQ读取这里描述的XML文件……

LINQ to read XML

LINQ to XML读

#6


-2  

Check out linq to XML

查看linq到XML