现有XML文档数据如下:
  <?xml version="1.0" encoding="GBK" ?> 
- <ROOT>
- <CONFIG>
  <TYPE>OUT</TYPE> 
  <WORKTYPE>1</WORKTYPE> 
  </CONFIG>
- <RESULT>
  <UNITCODE>5020100</UNITCODE> 
  <APPLYNO>ASHZH1104410D922232J</APPLYNO> 
  <POLICYNO /> 
  <APPLYENDORSENO /> 
  <STATUS_AUDITSTATUS>02</STATUS_AUDITSTATUS> 
  <COMMENTS>提交成功!</COMMENTS> 
  </RESULT>
  </ROOT>请问我用VB6.0如何得到每个节点之间的数据??如5020100
本人刚涉及VB。请各位多多指点!

解决方案 »

  1.   

    http://topic.csdn.net/u/20100128/11/1bfa7c8a-9d52-4a05-9b0d-eb7cefd2410a.html
      

  2.   

    我一般用的Microsoft XML v6.0
      

  3.   

    用DOM,Document Object Model,这个解析XML的对象,可以引用Microsoft XML, v6.0,一个简单的例子,创建两个XML节点,读取是一样的。更多可以参考http://www.w3school.com.cn/x.aspVERSION 5.00
    Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "comdlg32.ocx"
    Begin VB.Form XMLParse 
       BorderStyle     =   1  'Fixed Single
       Caption         =   "XMLParse"
       ClientHeight    =   4050
       ClientLeft      =   45
       ClientTop       =   330
       ClientWidth     =   5880
       BeginProperty Font 
          Name            =   "Arial Black"
          Size            =   9
          Charset         =   0
          Weight          =   400
          Underline       =   0   'False
          Italic          =   0   'False
          Strikethrough   =   0   'False
       EndProperty
       LinkTopic       =   "Form1"
       MaxButton       =   0   'False
       MinButton       =   0   'False
       ScaleHeight     =   4050
       ScaleWidth      =   5880
       StartUpPosition =   3  'Windows Default
       Begin VB.TextBox CodeText 
          Height          =   2295
          Left            =   240
          MultiLine       =   -1  'True
          TabIndex        =   3
          Top             =   840
          Width           =   5415
       End
       Begin VB.CommandButton Save 
          Caption         =   "Save"
          BeginProperty Font 
             Name            =   "Arial"
             Size            =   9.75
             Charset         =   0
             Weight          =   400
             Underline       =   0   'False
             Italic          =   0   'False
             Strikethrough   =   0   'False
          EndProperty
          Height          =   375
          Left            =   3360
          TabIndex        =   1
          Top             =   3480
          Width           =   975
       End
       Begin MSComDlg.CommonDialog CDialog 
          Left            =   5280
          Top             =   0
          _ExtentX        =   847
          _ExtentY        =   847
          _Version        =   393216
          Orientation     =   2
       End
       Begin VB.CommandButton Generate 
          Caption         =   "Generate"
          BeginProperty Font 
             Name            =   "Arial"
             Size            =   9.75
             Charset         =   0
             Weight          =   400
             Underline       =   0   'False
             Italic          =   0   'False
             Strikethrough   =   0   'False
          EndProperty
          Height          =   375
          Left            =   1200
          TabIndex        =   0
          Top             =   3480
          Width           =   975
       End
       Begin VB.Label XmlLableText 
          Caption         =   "XmlLableText"
          BeginProperty Font 
             Name            =   "Arial"
             Size            =   9.75
             Charset         =   0
             Weight          =   400
             Underline       =   0   'False
             Italic          =   0   'False
             Strikethrough   =   0   'False
          EndProperty
          Height          =   300
          Left            =   360
          TabIndex        =   2
          Top             =   360
          Width           =   5415
       End
    End
    Attribute VB_Name = "XMLParse"
    Attribute VB_GlobalNameSpace = False
    Attribute VB_Creatable = False
    Attribute VB_PredeclaredId = True
    Attribute VB_Exposed = False
          
    Option Explicit
       
    Private oXMLDom As MSXML2.DOMDocument
    Private oXMLElement As MSXML2.IXMLDOMElement
    Private oTemElement() As MSXML2.IXMLDOMElement
    Private oNodeAttr As MSXML2.IXMLDOMAttribute
    Private Sub Generate_Click()    Dim oThisNode As MSXML2.IXMLDOMNode
    '<--Create a new DOMDoc and then set the root element
        Set oXMLDom = CreateObject("MSXML2.DOMDocument")
        oXMLDom.async = False
        oXMLDom.validateOnParse = False
        Set oXMLElement = oXMLDom.createElement("Root")
        Set oXMLDom.documentElement = oXMLElement'<--Create the child nodes and set the attributes(or values) if needed
        ReDim oTemElement(0)
        Set oTemElement(0) = oXMLDom.createElement("Node")
        oXMLElement.appendChild oTemElement(0)
        oTemElement(0).setAttribute "NodeAttr", "AttributeOfThisNode"'<--Using dynamic object array to create nodes(attribute node)
        ReDim Preserve oTemElement(UBound(oTemElement) + 1)
        Set oTemElement(UBound(oTemElement)) = oXMLDom.createElement("Code")
        oTemElement(UBound(oTemElement) - 1).appendChild oTemElement(UBound(oTemElement))    Set oNodeAttr = oXMLDom.createAttribute("ChildNodeAttri")
        oTemElement(UBound(oTemElement)).setAttributeNode oNodeAttr
        oNodeAttr.Value = "ValueOfThisNodeAttr"    oTemElement(UBound(oTemElement)).Text = "Value Of this Element Node"
        
        Dim oCDATA As IXMLDOMCDATASection
        Dim sText As String
        
        'Here is the code can be from other place
        
        If CodeText.Text <> "" Then
            sText = CodeText.Text
        Else
            Set oXMLDom = Nothing
            Exit Sub
        End If
        
        Set oCDATA = oXMLDom.createCDATASection(sText)
        oTemElement(UBound(oTemElement)).appendChild oCDATA
        
        MsgBox "Generated Successful, Save"
        
        Save.Enabled = True End SubPrivate Sub Form_Load()
        Save.Enabled = False
        CodeText.Text = "Dim test : test=123 : Msgbox test"
        XmlLableText.Caption = "A CASE OF GENERATING XML FILE USING DOM...."
    End Sub
    Private Sub Save_Click()    On Error Resume Next
        Dim sFilePath As String    With CDialog
            .FileName = ""
            .MaxFileSize = 32767
            .DialogTitle = "Save"
            .Filter = "XML File(*.xml)|*.xml"
            .FilterIndex = 1
            .Flags = cdlOFNExplorer + cdlOFNOverwritePrompt
            .CancelError = True
            .Action = 2
            sFilePath = .FileName
        End With
        
        If Err = cdlCancel Then
            Exit Sub
        End If
        
        oXMLDom.Save (sFilePath)
        Set oXMLDom = Nothing
        XMLParse.Hide
        XMLReadCode.Show
    End Sub