Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/268.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 用C语言从xml文件中读取内容_C#_Xml - Fatal编程技术网

C# 用C语言从xml文件中读取内容

C# 用C语言从xml文件中读取内容,c#,xml,C#,Xml,我想在c中读取以下格式的内容表单xml文件。请让我知道 <Company> <Employee> <FirstName>FN</FirstName> <LastName>LN</LastName> </Employee> <Employee> <FirstName>FN1</FirstName> <LastName>SN1<

我想在c中读取以下格式的内容表单xml文件。请让我知道

<Company>
  <Employee>
    <FirstName>FN</FirstName>
    <LastName>LN</LastName>
  </Employee>
 <Employee>
   <FirstName>FN1</FirstName>
   <LastName>SN1</LastName>
 </Employee>
</Company>

使用以下类似xml linq的代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.Linq;

namespace ConsoleApplication58
{
    class Program
    {
        const string FILENAME = @"C:\TEMP\TEST.XML";
        static void Main(string[] args)
        {
            XDocument doc = XDocument.Load(FILENAME);

            List<KeyValuePair<string, string>> names = doc.Descendants("Employee")
                .Select(x => new KeyValuePair<string, string>((string)x.Element("FirstName"), (string)x.Element("LastName")))
                .ToList();


        }
    }
}

你尝试过的东西可能重复?你遇到了什么问题?可能的重复有很多可能。将其作为文本文件读取并逐行解析,编写基于对象的解析器。因此,它是为了帮助您解决代码中的错误,而不是为了完成您的工作。只需键入GoogleC.NETXMLParsei,我不想将其转换为拖放链接中提到的对象。我只想向最终用户显示xml文件中的内容