C# LINQ解析-如何以子对象为目标?
我有一个如下所示的XML文件:C# LINQ解析-如何以子对象为目标?,c#,xml,linq,C#,Xml,Linq,我有一个如下所示的XML文件: <options> <!-- Set the start page of the module --> <startpage>google.com</startpage> <alloweddomains> <domain>mail.google.com</domain> <domain>calendar.goog
<options>
<!-- Set the start page of the module -->
<startpage>google.com</startpage>
<alloweddomains>
<domain>mail.google.com</domain>
<domain>calendar.google.com</domain>
</alloweddomains>
</options>
它一直说我的allowedDomain是空思想(不是xdoc)。我是不是把域名定位错了?如果是,我如何定位域
谢谢大家的建议。您的
alloweddomains
元素中没有名为域的属性,您有元素
或者,假设您在其他任何地方都没有域元素,您只需执行以下操作即可
xdoc.Descendants("domain")
我讨厌XML!你完全正确。将在10分钟内将其标记为这样。聪明的话,@James。谢谢你的观点:)
xdoc.Descendants("alloweddomains").Elements("domain");
xdoc.Descendants("domain")