2009年2月6日 星期五

Visual Basic可以直接操作XML

Visual Basic 2008可以直接操作XML,例如直接將XML片段指定給XElement :

1 Dim x As XElement = <employee>

2 <id>1id>

3 <name>Maryname>

4 employee>

5 MsgBox(x.ToString())


若不想把XML的文字資料寫死,可以改用Expression:

1 Dim emp As Employee = New Employee()

2 emp.ID = "1"

3 emp.Name = "Mary"

4 Dim x As XElement = <employee>

5 <id><%= emp.ID %>id>

6 <name><%= emp.Name %>name>

7 employee>

8 MsgBox(x.ToString())


Employee類別如下:

1 Class Employee

2 Public ID As Integer

3 Public Name As String

4 End Class

沒有留言:

總網頁瀏覽量