?? clsxml.cls
字號:
VERSION 1.0 CLASS
BEGIN
MultiUse = -1 'True
Persistable = 0 'NotPersistable
DataBindingBehavior = 0 'vbNone
DataSourceBehavior = 0 'vbNone
MTSTransactionMode = 0 'NotAnMTSObject
END
Attribute VB_Name = "vbXML"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Option Explicit
'---------------------------------------------------
' vbXML : a set of functions designed to easily
' access the MSXML control provided by microsoft.
' vbXML may also be known as a class wrapper.
' vbXML attemps to re-create the MSXML interface by
' Providing a set of front-end methods and properties
' that access MSXML directly from the MSXML DLL file.
' Uses for vbXML could be easy skins, personalized
' settings (for forms), and anything else you could
' use the MSXML control for.
' See also : Readme.txt
'>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
' vbXML is based entirely on the CGoXML
' wrapper class submited to PlanetSourceCode by
' Roman Kehr, although vbXML is entirely my code
'
' I have made plenty of fixes and added many new
' features (or I plan to add new features), but I
' thought you must know about CGoXML, which greatly
' inspired vbXML
'>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
'>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
' In order to utilize most (if not all) of the
' functions included here you must understand
' (at least moderatley) XPath.
' What is XPath?
' XPath is used by MSXML to access specific nodes
' of an XML file
' How do I access a node?
' XPath (the way I use it) holds this format:
' "/parent1/child1/child2/childN/node"
' Where N is any number
' So to access a node, use this format:
' "/example/child/node"
'>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
' Any questions, comments, suggestions may be
' sent to:
' akartanis@akguild.com
'---------------------------------------------------
Dim xDoc As MSXML.DOMDocument
Public Enum OpenXMLDoc
oxFile = 0
oxString = 1
End Enum
Public Enum DocInfoConst
diVERSION = 0
diENCODING = 1
diSTANDALONE = 2
End Enum
'---------------------------------------------------
' Public Property Get
' XMLDocumentInfo
' Parameters
' diDesiredInfo As DocInfoConst : Tells the property
' what to look for
' What it does
' Gets the document info from the <?xml?> line
' Not entirely sure of funcyionality here
' No errors, just may change XPath a bit
' (By the way you reference a node)
' Author
' Anthony (11.19.02)
' Modified
' (11.19.02)
'---------------------------------------------------
Public Property Get XMLDocumentInfo(diDesiredInfo As DocInfoConst) As Variant
Dim strDesiredInfo As String
Select Case diDesiredInfo
Case diVERSION
strDesiredInfo = "version"
Case diENCODING
strDesiredInfo = "encoding"
Case diSTANDALONE
strDesiredInfo = "standalone"
End Select
Dim xNode As MSXML.IXMLDOMNode
Set xNode = xDoc.childNodes(0).Attributes.getNamedItem(strDesiredInfo)
XMLDocumentInfo = xNode.Text
Set xNode = Nothing
End Property
'---------------------------------------------------
' Function
' OpenXML
' Parameters
' strSource As String : The complete path and
' file name of the xml file to open
' Type As tOpenXML : Supplies to the function
' wether it should load from a file or a string
' What it does
' Opens strSource as an xml document ready for
' input (if oType is oxString then it loads from
' a string specified by strSource)
' Author
' Anthony (11.18.02)
' Modified
' (11.18.02)
'---------------------------------------------------
Public Function OpenXML(strSource As String, Optional oType As OpenXMLDoc = oxFile) As Boolean
Set xDoc = New MSXML.DOMDocument
Select Case oType
Case oxFile
OpenXML = xDoc.Load(strSource)
Case oxString
OpenXML = xDoc.loadXML(strSource)
End Select
End Function
'---------------------------------------------------
' Function
' ReadNode
' Parameters
' strQuery As String : The query string to be
' executed on the xml file
' What it does
' Executes the query strQuery on the xml file
' that has been opened and returns the value found
' in the node
' Author
' Anthony (11.18.02)
' Modified
' (11.18.02)
'---------------------------------------------------
Public Function ReadNode(strQuery As String) As String
On Error GoTo ErrHandle:
Dim xNode As MSXML.IXMLDOMNode
Set xNode = xDoc.documentElement.selectSingleNode(strQuery)
ReadNode = xNode.Text
Set xNode = Nothing
Exit Function
ErrHandle:
ReadNode = Null
Set xNode = Nothing
End Function
'---------------------------------------------------
' Function
' ReadNodeXML
' Parameters
' strQuery As String : The query string to be
' executed on the xml file
' What it does
' Executes the query strQuery on the xml file
' that has been opened and returns the full xml
' code for the node
' Author
' Anthony (11.18.02)
' Modified
' (11.18.02)
'---------------------------------------------------
Public Function ReadNodeXML(strQuery As String) As String
Dim xNode As MSXML.IXMLDOMNode
Set xNode = xDoc.documentElement.selectSingleNode(strQuery)
ReadNodeXML = xNode.xml
Set xNode = Nothing
End Function
'---------------------------------------------------
' Public Property Get
' XML
' Parameters
' (None)
' What it does
' Reads all of the XML data from the xml file and
' outputs as a string
' Author
' Anthony (11.18.02)
' Modified
' (11.18.02)
'---------------------------------------------------
Public Property Get xml() As String
xml = xDoc.xml
End Property
'---------------------------------------------------
' Function
' WriteNode
' Parameters
' strQuery As String : The query used to access the
' node
' Value As Variant : The value to be written to
' the node
' What it does
' Writes Value to the node specified by strQuery
' Author
' Anthony (11.18.02)
' Modified
' (11.18.02)
'---------------------------------------------------
Public Function WriteNode(strQuery As String, Value As Variant)
On Error GoTo ErrHandle:
Dim xNode As MSXML.IXMLDOMNode
Set xNode = xDoc.documentElement.selectSingleNode(strQuery)
xNode.Text = Value
Set xNode = Nothing
Exit Function
ErrHandle:
Set xNode = Nothing
End Function
'---------------------------------------------------
' Function
' ReadAttribute
' Parameters
' strQuery As String : The query used to access the
' node
' strName As String : The name of the attribute to
' read
' What it does
' Returns the value of the attribute specified by
' strName
' Author
' Anthony (11.18.02)
' Modified
' (11.18.02)
'---------------------------------------------------
Public Function ReadAttribute(strQuery As String, strName As String) As String
On Error GoTo ErrHandle:
Dim xNode As MSXML.IXMLDOMElement
Set xNode = xDoc.documentElement.selectSingleNode(strQuery)
ReadAttribute = xNode.getAttribute(strName)
Set xNode = Nothing
Exit Function
ErrHandle:
ReadAttribute = ""
Set xNode = Nothing
End Function
'---------------------------------------------------
' Function
' WriteAttribute
' Parameters
' strQuery As String : The query used to access the
' node
' strName As String : The name of the attribute
' to be written
' Value As Variant : The value to be written to
' the node attribute
' What it does
' Writes Value to the node attribute specified by
' strName in a node specified by strQuery
' Author
' Anthony (11.18.02)
' Modified
' (11.18.02)
'---------------------------------------------------
Public Function WriteAttribute(strQuery As String, strName As String, Value As Variant)
On Error GoTo ErrHandle:
Dim xNode As MSXML.IXMLDOMElement
Set xNode = xDoc.documentElement.selectSingleNode(strQuery)
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -