VB.NET2005读取XML数据
通过调用CreateDataSetfromXml取得XML数据
Imports System.Xml
Public Const FILE_CONFIG = "MZZ.xml"
Public Const PATH_CONFIG = "\XML\"
Dim dstXML As DataSet
Dim tblXML_DB As DataTable
Dim dtCod As New DataTable
Dim strSQL As String = ""
clsPublic.pstrAppPath = System.Windows.Forms.Application.StartupPath'启动程序路径
'启动程序上级目录(InStrRev是取得最后显示\的位置)
clsPublic.pstrAppPath = Mid(clsPublic.pstrAppPath, 1, InStrRev(clsPublic.pstrAppPath, "\", ) - 1)
'只能启动一个程序
If UBound(Diagnostics.Process.GetProcessesByName(Diagnostics.Process.GetCurrentProcess.ProcessName)) > 0 Then
Exit Sub
End If
'读取XML数据(QDIS节点,作为一个table,所以是dstXML.Tables(0))
dstXML = CreateDataSetfromXml(FILE_CONFIG)
tblXML_DB = dstXML.Tables(0)
clsDBBase.Uid = tblXML_DB.Rows(0).Item("UserId")
clsDBBase.Psw = tblXML_DB.Rows(0).Item("Password")
clsDBBase.Dsn = tblXML_DB.Rows(0).Item("DataSource")
'(APPL节点,作为一个table,所以是dstXML.Tables(1))
clsPublic.Timer_Interval = CType(dstXML.Tables(1).Rows(0).Item("Interval"), Integer)
'内存整理
GC.Collect()
Public Function CreateDataSetfromXml(ByVal strFileName As String) As DataSet
Dim xmlDoc As XmlDataDocument = New XmlDataDocument
Dim xmlReader As StreamReader = Nothing
Try
xmlReader = New StreamReader(clsPublic.pstrAppPath & PATH_CONFIG & strFileName)
xmlDoc.DataSet.ReadXml(xmlReader, XmlReadMode.Auto)
Return xmlDoc.DataSet.Copy
Catch ex As Exception
Return Nothing
Finally
Try
If Not xmlReader Is Nothing Then
xmlReader.Close()
xmlReader = Nothing
End If
相关文档:
今天想要做类似金山词霸屏幕取词的功能,在网上找了一些资料,发现都很复杂。既然金山词霸已经实
现了,借用之:
金山词霸中2005中带了一个XdictGrb.dll,其实是一个COM组件,并且实现了一个取词的插件框架。
其中的有以下内容:
1 接口
1.1 GrabProxy 取词代理对象
Function AdviseGrab(XDictGrabSink As IXDictGra ......
已知有一个XML文件(bookstore.xml)如下:
<?xml version="1.0" encoding="gb2312"?>
<bookstore>
<book genre="fantasy" ISBN="2-3631-4">
<title>Oberon's Legacy</title>
<author>Corets, Eva</author>
&nb ......
前面文章中提到 xml节点的删除
“删除 <book genre="fantasy" ISBN="2-3631-4">节点的genre属性,删除 <book genre="update陶维佳" ISBN="2-3631-4">节点。”
代码:
XmlNodeList xnl=xmlDoc.SelectSingleNode("bookstore").ChildNodes;
foreach(XmlNode&nbs ......
※==================================================================
※本连载文章说明:
※1、连载首发于《软件报》(http://www.sweek.com)2006年21期(2006年5月22日);
※2、此次网上连载采用的是原稿件结构,内容与《软件报》发表略有不同;
※3、谢绝除《软件报》及其相关刊物之外的传统媒体部分或全部转载 ......