一直在嘗試,並沒有得到任何工作結果。如何按位置選擇XML節點(Linq或XPATH)
鑑於是Excel這樣的XML結構:
<?xml version="1.0"?>
<?mso-application progid="Excel.Sheet"?>
<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet"
xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:x="urn:schemas-microsoft-com:office:excel"
xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"
xmlns:html="http://www.w3.org/TR/REC-html40">
<DocumentProperties xmlns="urn:schemas-microsoft-com:office:office">
...
</DocumentProperties>
<OfficeDocumentSettings xmlns="urn:schemas-microsoft-com:office:office">
...
</OfficeDocumentSettings>
<ExcelWorkbook xmlns="urn:schemas-microsoft-com:office:excel">
...
</ExcelWorkbook>
<Styles>
...
</Styles>
<Worksheet ss:Name="Report">
<Table ss:ExpandedColumnCount="41" ss:ExpandedRowCount="4082" x:FullColumns="1"
x:FullRows="1" ss:DefaultColumnWidth="60" ss:DefaultRowHeight="15">
<Row>
<Cell ss:StyleID="s62"><Data ss:Type="String">Cell_1</Data></Cell>
<Cell ss:StyleID="s62"><Data ss:Type="String">Cell_2</Data></Cell>
...
<Cell ss:StyleID="s62"><Data ss:Type="String">Cell_40_Active</Data></Cell>
</Row>
<Row>
<Cell ss:StyleID="s62"><Data ss:Type="String">Cell_1</Data></Cell>
<Cell ss:StyleID="s62"><Data ss:Type="String">Cell_2</Data></Cell>
...
<Cell ss:StyleID="s62"><Data ss:Type="String">Cell_40_Active</Data></Cell>
</Row>
</Table>
<WorksheetOptions xmlns="urn:schemas-microsoft-com:office:excel">
...
</WorksheetOptions>
</Worksheet>
</Workbook>
目標是隻選擇這些行,其中包含的行的「Cell_40_Active」 40-小區(ID)之內。像:細胞[40] .Data.InnerText = 「Cell_40_Active」 ......
XmlDocument doc = new XmlDocument();
doc.Load(file);
XmlElement root = doc.DocumentElement;
// does return all Row-elements >> working
XmlNodeList nodes = root.GetElementsByTagName("Row");
//does not return any element (0)
XmlNodeList nodes = root.SelectNodes("/Worksheet/Row/Cell[40]='Cell_40_Active'");
如何才能做到這一點?還沒有找到類似的... 任何提示?非常感謝你。
這個伎倆......謝謝你,老兄! – SiL3NC3