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 ......
Ò»¡¢Îĵµ¶ÔÏóÄ£ÐÍ£¨DOM£©
¡¡¡¡DOMÊÇDocument Object Model£¨Îĵµ¶ÔÏóÄ£ÐÍ£©µÄ¼ò³Æ£¬ÊǶÔXMLÎĵµ½øÐÐÓ¦Óÿª·¢¡¢±à³ÌµÄÓ¦ÓóÌÐò½Ó¿Ú£¨API£©¡£×÷ΪW3C¹«²¼µÄÒ»ÖÖ¿çƽ̨¡¢ÓëÓïÑÔÎ޹صĽӿڹ淶£¬DOMÌṩÁËÔÚ²»Í¬»·¾³ºÍÓ¦ÓÃÖеıê×¼³ÌÐò½Ó¿Ú£¬¿ÉÒÔÓÃÈκÎÓïÑÔʵÏÖ¡£
¡¡¡¡DOM²ÉÓöÔÏóÄ£ÐͺÍһϵÁеĽӿÚÀ´ÃèÊöXMLÎĵµµÄÄÚÈݺͽ ......
1 ÀàËÆxmlns=""µÄÎļþ
ʾÀýXMLÎļþ:
<?xml version="1.0" encoding="UTF-8"?>
<WebSrvMessage xmlns="http://www.lenoval.com/">
<version>1.0</version>
<DataContent>
<DateTag>2010-5-17</DateTag>
</DataCont ......
Îå¡¢XMLģʽ
l XMLģʽÄܸü¾«È·µÄ´¦ÀíXML½á¹¹Ô¼ÊøµÄ±íʾ֮Í⻹ΪԼÊøÊý¾ÝµÄ´¦ÀíÌṩһ¸öXMLÑùʽ¡£Ä£Ê½Ö»ÊÇÒ»¸öXMLÎĵµ£¬ÊÜDTDµÄÔ¼Êø¡£¶ÔÓÚXMLģʽ¶øÑÔ£¬XML DTDÖ»ÊÇÒ»ÖÖ´´½¨ÎĵµÔ¼ÊøµÄÊֶΡ£ÒòΪXMLģʽÊÇΪÁËÇ¿»¯XMLÎĵµµÄÓÐЧÐÔ£¬Ëü±ØÐë²ÉÓÃÒ»ÖÖ»úÖÆ£¬¶ø²»ÊÇ×Ô¼º¶¨ÒåÔ¼ÊøÌõ¼þ¡£ÕâÖÖ»úÖƱØÐëÊÇÒ»¸öDTD¡£µ«ÊÇÔʼµÄD ......