如何读取XML在C#中?XML

2023-09-03 07:06:32 作者:我的五杀你抢不了¥

我有一个看起来像这样的XML文件

I have an XML file which looks like this

<ss:demo>
<ss:Name>
    <ss:FirstName>First</ss:FirstName>
    <ss:SecondName>Second</ss:SecondName>
</ss:Name>
<ss:country code="IN">India</ss:country>
</ss:demo>

我如何阅读本使用C#。 请帮我在这。这将是最简单的方式阅读了吗?我想读入数据集,但它表现出一些错误。

How can I read this using C#. Please help me in this. which will be easiest way for reading it? I tried to read it into a DataSet but its showing some error.

推荐答案

有几种策略来读取XML文件,或其部分,使用C#。如果你有更具体的了解你想要做的与XML文档什么的,社区可为您提供更具体的指导。

There are several strategies to read an XML document, or parts thereof, using C#. If you are more specific about what you want to do with the XML document, the community can provide you with more specific guidance.

下面是一些最佳选择:

的LINQ to XML

Linq to XML

http://msdn.microsoft.com/en-us/library/bb387098.aspx

http://msdn.microsoft.com/en-us/library/bb387065.aspx

的XDocument(LINQ的一部分,以XML框架)

XDocument (part of the Linq to XML framework)

http://msdn.microsoft.com/en-us/library/bb387063.aspx

XmlDocument的

XmlDocument

http://msdn.microsoft.com/en-us/library/system.xml.xmldocument.aspx

的XPath

http://msdn.microsoft.com/en-us/library/ms256471.aspx