在C#中读取大型XML文件,在查找元素时返回null

问题描述 投票:0回答:1

我需要读取一个大的XML文件,但是我尝试过的所有内容都返回NULL。

public void readXml()
{
  XElement xelement = XElement.Load(DewesoftDevices.xmlFileName);
  IEnumerable<XElement> devices = xelement.Elements("Devices");

  foreach (var device in devices)
  {
     Console.WriteLine(device);
  }
}

这里是xml文件的一部分:

<?xml version="1.0" encoding="UTF-8"?>
<DataFileSetup>
    <System Name="Local">
        <SysInfo>
         'Stuff in here that I dont need
        </SysInfo>
        <DewesoftSetup>
           <Devices>
               <StartStoreTime>43861.6768385532</StartStoreTime>
               <SampleRate>100</SampleRate>
               <BlockSize>1000</BlockSize>
               <IBRate>10</IBRate>
           </Devices>
        </DewesoftSetup>
    </System>
</DataFileSetup>

我不知道这是否重要,但这些文件远不及文件中的。

c# xml linq-to-xml
1个回答
1
投票

请尝试以下操作:

© www.soinside.com 2019 - 2024. All rights reserved.