如何保存XML文件中的数据以及如何从ASP.net中的XML文件读取数据

如何保存XML文件中的数据以及如何从ASP.net中的XML文件读取数据

问题描述:

我想在XML文件中保留一些数据,并且在页面加载时需要读取xml
我该怎么做?

i want to preserve some data in XML file and on page load need to read that xml
how can i do it?

.NET中有几种不同的XML持久性方法.您不必手动"使用XML.我建议使用Data Contract.它有助于存储和恢复任何对象图,而不会影响数据类型的声明.您只需将[DataContract][DataMember]之类的属性添加到声明中并使用DataContractSerializer.

请参阅 http://msdn.microsoft.com/en-us/library/ms733127.aspx [ ^ ].

另请参阅我过去的答案:
如何在我的表单应用程序? [ ^ ],
创建属性文件... [
There are several different approached to XML persistence in .NET. You don''t have to work with XML "manually". I would advice using Data Contract. It helps to store and restore any object graph without any intrusion into declaration of data types. You only add attributes like [DataContract] and [DataMember] to declarations and use the DataContractSerializer.

See http://msdn.microsoft.com/en-us/library/ms733127.aspx[^].

See also my past answers:
How can I utilize XML File streamwriter and reader in my form application?[^],
Creating a property files...[^].

—SA