如下XML,我看微软关于XContainer.Elements()方法的介绍是:按文档顺序返回此元素或文档的已筛选的子元素集合。 集合中仅包括具有匹配 XName 的元素。
<?xml version="1.0" encoding="utf-8" ?>
<Config>
<Products>
<Prod Name="PN50A">
<LotTypes Thick="True" Thin="Flase">
<LotType Name="PRD">
<Max Count="5">1,21</Max>
<Min Count="5">All</Min>
</LotType>
<LotType Name="REG">
<Max Count="5">1,21</Max>
<Min Count="5">All</Min>
</LotType>
</LotTypes>
</Prod>
</Products>
</Config>
但是:
//第一种
XElement doc=XElement.Load(Path);
var LotTypes = doc.Elements("LotTypes"); // Count =0 ?
//第二种
doc.Element("Products").Elements("Prod").Elements("LotTypes").Elements("LotType");
var LotTypes = doc.Elements("LotTypes"); // Count >0
为什么第一种会是0呢?请大家帮忙解答!
Elements(xName)不能直接去找子节点吗?必须要一级级的去找吗