ITPub博客

首页 > Linux操作系统 > Linux操作系统 > vb.net LINQ TO XML读写XML

vb.net LINQ TO XML读写XML

原创 Linux操作系统 作者:iDotNetSpace 时间:2009-02-11 16:27:01 0 删除 编辑
 1Imports System.Linq
 2Imports System.Xml.Linq
 3
 4Public Class xmlDemoClass xmlDemo
 5    Public Shared Sub CreateXml()Sub CreateXml()
 6        Dim ld As New List(Of Object)
 7        ld.Add(New With {.ID = "1", .Name = "人事"})
 8        ld.Add(New With {.ID = "2", .Name = "业务"})
 9
10
11        Dim lp As New List(Of Object)
12        lp.Add(New With {.ID = "1", .Name = "jim", .DID = "1"})
13        lp.Add(New With {.ID = "2", .Name = "tony", .DID = "2"})
14        lp.Add(New With {.ID = "3", .Name = "jesson", .DID = "2"})
15
16
17        Dim person =
18                         <%= From p In lp Where p.ID _
19                             Select
20                                        <%= p.ID %>
21                                        <%= p.Name %>
22                                   
%>
23
24                    

25        person.Save("C:\persons.xml")
26        Process.Start("C:\persons.xml")
27
28        Dim departMent = <%= From d In ld _
29                                         Select
30                                                    <%= d.id %>
31                                                    <%= d.name %>
32                                                   
33                                                        <%= From p In lp Where p.did = d.id _
34                                                            Select
35                                                                       <%= p.id %>
36                                                                       <%= p.name %>
37                                                                  
%>
38                                                   

39                                               
%>
40                        

41        departMent.Save("c:\departMent.xml")
42        Process.Start("c:\departMent.xml")
43
44      
45    End Sub
46    Public Shared Sub readXML()Sub readXML()
47      
48        Dim xdoc = XDocument.Load("C:\persons.xml")
49        Dim ps = From p In xdoc.Descendants("person") _
50                Select New With {.ID = p.Element("ID").Value, .Name = p.Element("Name").Value}
51        For Each p In ps
52            MsgBox(p.ID & Space(3) & p.Name)
53        Next
54    End Sub
55End Class
56
57

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/12639172/viewspace-548714/,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2008-01-04

  • 博文量
    2376
  • 访问量
    5327726