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
相关文档:
常用的系列化定义(using System.Xml.Serialization;)
[XmlAttribute("name")] // 定义<Tag name="…"></Tag>
[XmlElement("label")] // 定义<label>…</label>
[XmlIgnoreAttrib ......
代码如下:
DECLARE
@TempTable table(UserID int , UserName nvarchar(50));
insert into
@TempTable (UserID,UserName) values (1,'a')
insert into @TempTable
(UserID,UserName) values (2,'b')
select UserID,UserName
from @TempTable FOR XML PATH
运行这段脚本,将生成如下结果:
复制代码
......
Introduction
This article is about passing data between VB.NET/C# WinForms and JavaScript.
Before reading further, let me warn you that this article is not about ASP.NET. Concepts covered in the article are applied to Desktop applications.
Background
I was working on a project which required dat ......
已知有一个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模式
l XML模式能更精确的处理XML结构约束的表示之外还为约束数据的处理提供一个XML样式。模式只是一个XML文档,受DTD的约束。对于XML模式而言,XML DTD只是一种创建文档约束的手段。因为XML模式是为了强化XML文档的有效性,它必须采用一种机制,而不是自己定义约束条件。这种机制必须是一个DTD。但是原始的D ......