【发布时间】:2020-02-12 20:01:36
【问题描述】:
我需要读取一个大型 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>
我不知道这是否重要,但这些都在文件中。
【问题讨论】:
-
实际上,我对开头的内容更感兴趣。一个常见的错误是忘记考虑 XML 命名空间 (
xmlns)。 -
请提供minimal reproducible example 并确保小数据样本(类似于已在帖子中的样本)实际证明了问题。特别要确保为您尝试查询的节点提供所有相关的命名空间。
-
我添加了更多的 XML 代码。
-
XML 文件的大小是多少?
-
大约 500 kb
标签: c# xml linq-to-xml