如何从c#中的windows表单应用程序中读取xml文件

时间:2021-02-25 09:17:21

How to read xml file from windows form application in c#? I am new in this .net framework prograaming. I have 3.5 .net framework please give simple program for it

如何从c#中的windows表单应用程序中读取xml文件?我是这个.net框架编程的新手。我有3.5 .net框架请给它简单的程序

2 个解决方案

#1


5  

The simplest way to read an XML file into memory is to use the XDocument.Load method. This method takes a file path and returns an XDocument instance which can be used to query the contents

将XML文件读入内存的最简单方法是使用XDocument.Load方法。此方法采用文件路径并返回可用于查询内容的XDocument实例

XDocument doc = XDocument.Load(@"c:\path\to\the\xmlfile.xml");

If you're working with an older API, you may need to use the XmlDocument class. It can be loaded in the following way

如果您使用的是较旧的API,则可能需要使用XmlDocument类。它可以通过以下方式加载

XmlDocument doc = new XmlDocument();
doc.Load(@"c:\path\to\the\xmlfile.xml");

#2


2  

If you're using .Net 3.5 or later, you can use the XDocument class to read and write XML.

如果您使用的是.Net 3.5或更高版本,则可以使用XDocument类来读取和写入XML。

If you're still in .Net 2.0, you can use the XmlDocument class.

如果您仍在.Net 2.0中,则可以使用XmlDocument类。

#1


5  

The simplest way to read an XML file into memory is to use the XDocument.Load method. This method takes a file path and returns an XDocument instance which can be used to query the contents

将XML文件读入内存的最简单方法是使用XDocument.Load方法。此方法采用文件路径并返回可用于查询内容的XDocument实例

XDocument doc = XDocument.Load(@"c:\path\to\the\xmlfile.xml");

If you're working with an older API, you may need to use the XmlDocument class. It can be loaded in the following way

如果您使用的是较旧的API,则可能需要使用XmlDocument类。它可以通过以下方式加载

XmlDocument doc = new XmlDocument();
doc.Load(@"c:\path\to\the\xmlfile.xml");

#2


2  

If you're using .Net 3.5 or later, you can use the XDocument class to read and write XML.

如果您使用的是.Net 3.5或更高版本,则可以使用XDocument类来读取和写入XML。

If you're still in .Net 2.0, you can use the XmlDocument class.

如果您仍在.Net 2.0中,则可以使用XmlDocument类。