0
考慮下面的XML我想找到所有的成本值,並找到相關AltID的如何使用linq搜索同胞?
...
<Row ss:AutoFitHeight="0">
<Cell ss:StyleID="s62"><Data ss:Type="String" AltID="1" ColumnHeader="AltName">Alternative 2</Data></Cell>
<Cell ss:StyleID="s62"><Data ss:Type="Number" ColumnHeader="Total">0.105468638</Data></Cell>
<Cell ss:StyleID="s64"><Data ss:Type="Number" ColumnHeader="Cost">123</Data></Cell>
<Cell ss:StyleID="s64"><Data ss:Type="Number" ColumnHeader="Risk">456</Data></Cell>
</Row>
<Row ss:AutoFitHeight="0">
<Cell ss:StyleID="s62"><Data ss:Type="String" AltID="2" ColumnHeader="AltName">Alternative 3</Data></Cell>
<Cell ss:StyleID="s62"><Data ss:Type="Number" ColumnHeader="Total">1.7803949999999999</Data></Cell>
<Cell ss:StyleID="s64"><Data ss:Type="Number" ColumnHeader="Cost">123</Data></Cell>
<Cell ss:StyleID="s64"><Data ss:Type="Number" ColumnHeader="Risk">456</Data></Cell>
</Row>
...
我能找到的成本很容易(這是兩列在Excel XML數據表),但我需要找到一種方法來說,用這個給定的成本,去「上」一個級別行,然後找到其ColumnHeader等於AltName,然後給我的AltID屬性的單元格。
Dim costs = From item In dg...<Table>...<Row>...<Cell>...<Data> Select item Where [email protected] = "Cost"
For Each i In costs
dim CostValue as Integer = i.value
dim AltID as Integer = ...
Next
爲什麼要使用linq?爲什麼不使用簡單的XPath查詢? –