简体   繁体   English

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

[英]How to read xml file from windows form application in c#

How to read xml file from windows form application in c#? 如何从c#中的windows表单应用程序中读取xml文件? I am new in this .net framework prograaming. 我是这个.net框架编程的新手。 I have 3.5 .net framework please give simple program for it 我有3.5 .net框架请给它简单的程序

The simplest way to read an XML file into memory is to use the XDocument.Load method. 将XML文件读入内存的最简单方法是使用XDocument.Load方法。 This method takes a file path and returns an XDocument instance which can be used to query the contents 此方法采用文件路径并返回可用于查询内容的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. 如果您使用的是较旧的API,则可能需要使用XmlDocument类。 It can be loaded in the following way 它可以通过以下方式加载

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

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类。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 C# Windows 应用程序中从 xml 文件中获取/读取数据 - How to get/read data from the xml file in C# Windows application 如何在C#表单应用程序中使用xml基于xml文件中的用户输入获取标签的文本 - How to use xml with c# form application To get text for Lables Based on user Input from xml file 在C#Windows应用程序中从文本文件读取特定单词 - Read specific word from text file in C# windows application 如何使用C#4.0从Windows应用程序的客户端中读取服务器中的文本文件 - how to read text file in server from client in windows application using C# 4.0 c#如何将pdf文件包含到我的Windows窗体应用程序中 - c# how to inclued a pdf file to my windows form application C#:如何在Windows应用程序中从Web浏览器读取数据 - C#: How to read data from webbrowser in a windows application 如何从C#Windows应用程序中的运行模式识别表单设计器文件? - How to Identify form designer file from running mode in C# windows application ? 如何在C#中从Windows窗体应用程序项目设置.dll文件的路径? - How to set path of .dll file from windows form application project in C#? 如何通过调整大小来修复C#Windows窗体应用程序的大小 - How to fix the size of a C# Windows Form Application from resizing 如何从Outlook启动C#Windows窗体应用程序? - How to launch a C# windows form application from Outlook?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM