对,☆浪人☆说的没错,微软的msxml4.0在VB中就是一个组件,new就可以了.生成了Document以后,就可以读写增加修改酸除node了.我做了一个解析DOM书的例子,请看.
Private Sub CmdOpenXml_Click()
Dim LsHour As String
Dim LsMin As String
Dim LsSec As String
Dim TimeB As String
Dim TimeE As String
Dim msTime As String
Dim lTime As SystemTime
Dim bM, eM As Integer
Dim bMs, eMs As Integer
Dim bMm, eMm, costTime As Integer
Dim Rslt As Variant
Dim Node As IXMLDOMNode 'ノードを取得
Dim Rootdoc As DOMDocument 'ルートノードをゲット
'XMLファイルのデータを読み込む、フィールドまで分ける
LstTree.Clear
Set Rootdoc = New DOMDocument
Rootdoc.async = False '非同期処理を行わない
Rootdoc.validateOnParse = False '文書型定義を検証しない
Rootdoc.preserveWhiteSpace = False 'WhiteSpaceを含めない
If (Rootdoc.Load(XMLFILE)) Then
Set Node = Rootdoc.childNodes(1)
Rslt = getNodeData(Node)
End If
Private Function getNodeData(ByVal nodeData As IXMLDOMNode) As Variant
Dim rt As Variant
Dim i, j, num, chnt As Integer
Dim atrrName, atrrValue, RecordData As String
Dim NodeMap As IXMLDOMNamedNodeMap 'ノードの属性を取得
RecordData = nodeData.nodeName
'当ノートの属性を判断、つまり、要素の属性が有否を判断する
Set NodeMap = nodeData.Attributes
num = NodeMap.Length
If num > 0 Then
For i = 0 To num - 1
atrrName = NodeMap.Item(i).nodeName '要素の属性の名前
atrrValue = NodeMap.Item(i).nodeValue '要素の属性の値
RecordData = RecordData + atrrName & ":" & atrrValue
Next i
LstTree.AddItem (RecordData)
'当ノートは子ノートがあれば、コールセルフ
If (nodeData.hasChildNodes) Then
chnt = nodeData.childNodes.Length
For j = 0 To chnt - 1
rt = getNodeData(nodeData.childNodes(j))
Next j
Else
'当ノートは子ノートが無し、これはDOMツリーの最後の階層
Exit Function
End If
End If
End Function
TXMLDocument
TXMLDocument is a component used for programming XML documents. It takes car
e of getting an instance of a IDOMDocument interface and loading and saving
xml files. After setting the filename property and setting Active to true, u
se the DOMDocument property to access the contents of the file.