我對名稱空間是如何工作感到困惑。我試圖讓worksheet
其中ss:Name="Datagrid"
,並從獲得data
節點,在name="emailname"
如何使用名稱空間使用...語法創建linq查詢
Imports <xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet">
Module Module1
Sub Main()
Dim xmlFile As String = System.AppDomain.CurrentDomain.BaseDirectory & "Datagrid.xml"
Dim root As XElement = XElement.Load(xmlFile)
''select worksheet where ss:Name="Datagrid""
'Dim dg = From item In root .......................
''get data from wokrsheet...table..row...data where = name="emailname" (not ss:name="emailname")
'Dim data = From item In dg .......................
End Sub
End Module
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">
<Worksheet ss:Name="Datagrid">
<Table ss:ExpandedColumnCount="13" ss:ExpandedRowCount="11" x:FullColumns="1"
x:FullRows="1" ss:DefaultRowHeight="15">
<Row ss:Index="3" ss:AutoFitHeight="0">
<Cell Name="emailname">
<Data ss:Type="String">email address</Data>
</Cell>
</Row>
<Row ss:Index="4" ss:AutoFitHeight="0">
<Cell Name="username">
<Data ss:Type="String">user name</Data>
</Cell>
</Row>
</Table>
</Worksheet>
<Worksheet ss:Name="Properties">
<Table ss:ExpandedColumnCount="1" ss:ExpandedRowCount="3" x:FullColumns="1"
x:FullRows="1" ss:DefaultRowHeight="15">
<Row>
<Cell>
<Data ss:Type="Number">1</Data>
</Cell>
</Row>
<Row>
<Cell>
<Data ss:Type="Number">2</Data>
</Cell>
</Row>
<Row>
<Cell>
<Data ss:Type="Number">3</Data>
</Cell>
</Row>
</Table>
</Worksheet>
</Workbook>
嘿,你已經在使用這個語法「'按照項@ SS:Name'「!那麼我是否誤解了你的問題? – 2012-08-17 13:29:32
我這樣想,我試圖得到datagrid其ss:Name =「Datagrid」,並從那得到節點的名稱=「data」(不是ss:name =「data」) – WhiskerBiscuit 2012-08-17 15:11:49
注意默認命名空間'xmlns')與'xmlns:ss'相同,所以'name'和'ss:name'是相同的。 – 2012-08-17 18:14:42