【发布时间】:2009-12-21 23:18:18
【问题描述】:
我加载了一个具有以下结构的 XML 文档:
<?xml version="1.0" encoding="UTF-8" ?>
<worksheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships">
<sheetData>
<row r="1" spans="1:2">
<c r="A1" t="s">
<v>0</v>
</c>
<c r="B1" t="s">
<v>1</v>
</c>
</row>
</sheetData>
</worksheet>
我想在文档中查询任何名为 c 且具有属性 t = s 的元素。
我已经尝试了很多不同的方法来做到这一点:
XDocument xmlDoc = XDocument.Load(@"..\..\Sheet1.xml");
var rows = from row in xmlDoc.Root.Descendants("worksheet").Elements("sheetData")
select row;
但它总是返回一个空集。
我错过了什么?
【问题讨论】:
标签: c# .net xml linq linq-to-xml