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

Reading Large XML files in C# Returns null when looking for an element

我需要读取一个大 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#

XDocument xdoc = XDocument.Load(DewesoftDevices.xmlFileName)
var devices = xdoc.Descendants("Devices");
foreach (XElement x in devices)
{
    Console.WriteLine(x);

}