linq學習筆記2

VB中對linq to xml 的支持

1. XML字面值

dim book  = <book title="title">
                    <Author>dm</Author>
                   </book>

2. 動態XML

dim tag = "Description"
dim simple = <<%= tag %>>description simple </>
'注意<%=  %> 要有空格  
'結束標籤 </>

3. 與Linq的結合, 產生XML

dim book = _
    <book>
        <%= from person in team _
where person.Role
= "Author" _
       select <author><%= person.Name %></author> %> </book>

4. 使用linq 讀取XML

child axis:<Genre> 會轉化為Elements() 方法

attribute axis: @Tilte 會轉化為Attribute() 方法

descendants axis: 可以取得一個element所有的子孫 , 用 ... 表示 與child axis類似 如: movies...<Diretor>

dim movies = _
<Movies>
    <Movie Title="test">
         <Genre>Gim</Genre>
         <Genre>Drama</Genre>
         <Diretor>David</Diretor>
    </Movie>
</Movies>

dim a = from movie in movies.<Movie> _
            where movie.@Title ="test" _
            select movie).First()
'取得所有Genre
'相當於: a.Elements("Genre")
for each g in a.<Genre>
...
next

VB中沒有 yield關鍵字

VB中沒有匿名方法, 可以使用lambda表達式代替, 但lambda表達式無法取代 匿名delegate

後續的學習中會詳細的介紹Linq To XML

 

 

 

posted @ 2013-04-17 11:32  邪见  阅读(160)  评论(0)    收藏  举报