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",Arial; line-height:26px">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