【发布时间】:2013-08-13 10:20:55
【问题描述】:
我需要获取一个子主题元素的值,该元素具有一个名为“名称”的attribute,具有特定值。我是这样做的;
IEnumerable<XElement> list =
(from el in xdoc.Elements()
where (string)el.Attribute("Name") == "creatingTests"
select el);
该集合有零个元素。
我尝试使用xdoc.Elements("SubTopic") 代替空参数,但没有成功。
我的 XML 文件结构;
<?xml version="1.0" encoding="windows-1250" ?>
<Help Title="TestTool - tematy pomocy">
<Topic Name="creatingTests" Title="Tworzenie testów">
<SubTopic Name="saveload" Title="Zapis i odczyt z pliku">
Content
</SubTopic>
</Topic>
</Help>
如何获得 Help/Topic(Name="creatingTests") 的值?
xdoc 当然是 XDocument 加载了 xml 的对象,它确实包含我文件的内容。
【问题讨论】:
标签: c# xml linq-to-xml