首先一个名称为DATA.XML文件,内容如下
<?xml version="1.0" encoding="utf-8" ?> <mykeys> <myitem ID="1" order="1" kyes="F1" title="F1标题"> F1内容F1内容F1内容F1内容F1内容 F1内容F1内容F1内容 F1内容F1内容 F1内容 F1内容F1内容F1内容 </myitem> <myitem ID="2" order="2" kyes="F2" title="F2标题"> F2内容 F2F2内容F2内容F2内容 F2内容F2内容F2内容F2内容 F2内容F2内容F2内容F2内容 F2内容 </myitem> </mykeys>
建立一个操作类,
Public Class myKeysXml Public Structure DTinf Public ID As Integer Public order As Integer Public kyes As String Public title As String Public sbody As String End Structure End Class
使用之前导入
Imports System.Xml.Linq
下面是点击一个按钮执行的操作。
Private Sub Button1_Click(sender As Object,e As EventArgs) Handles Button1.Click Dim SXML As XElement = XElement.Load(Application.StartupPath & "\data.xml") If SXML Is Nothing Then Exit Sub Dim Rows = From item In SXML.Elements("myitem") Order By item.Attribute("order").Value Select item Dim itemList As New List(Of myKeysXml.DTinf) For Each it As XElement In Rows Dim item As New myKeysXml.DTinf item.ID = it.Attribute("ID")Value item.kyes = it.Attribute("kyes")Value item.order = it.Attribute("order")Value item.title = it.Attribute("title")Value item.sbody = it.Value itemList.Add(item) Next End Sub取得itemList的序列,然后大家怎么使用就可以自由发挥了。
原文链接:https://www.f2er.com/vb/257722.html