Unable to read the attributes of child nodes using XML DOM in Access 2003

后端 未结 1 417
清酒与你
清酒与你 2021-01-21 17:44

I have searched the web for perhaps 8 hours including Experts Exchange and Stackoverflow and have found others with the same issue but I\'ve not found a solution to this issue.

1条回答
  •  青春惊慌失措
    2021-01-21 17:59

    Always validate xml string when there is issue to parse it,

    Verify Your XML Syntax

    Copy your string to know if its error free.

    Updated XML

    
        
            
                   
            
            
                  
            
            
                 
                 
            
        
    
    

    Function ReadAttributes(ByVal strXML As String)
    
        Dim xmldoc As New DOMDocument
        Dim iNode As MSXML2.IXMLDOMNode
        Dim iNode2 As MSXML2.IXMLDOMNode
        Dim DonorNodeList As IXMLDOMNodeList
        Dim iAtt As IXMLDOMAttribute
        Dim iAtt2 As IXMLDOMAttribute
    
        On Error GoTo ReadAttributes_OnError
    
        xmldoc.async = False
        xmldoc.LoadXML strXML
        If xmldoc.parseError.ErrorCode <> 0 Then
            MsgBox "Invalid XML, Load Failed"
            GoTo ReadAttributes_OnError
        End If
    
        Set DonorNodeList = xmldoc.getElementsByTagName("Donor")
    
        For Each iNode In DonorNodeList
            For Each iAtt In iNode.Attributes
                MsgBox iAtt.Name & ": " & iAtt.nodeTypedValue
            Next
    
    
            Set iNode2 = xmldoc.getElementsByTagName("Donor")(0)
    
            For i = 0 To iNode2.ChildNodes.Length - 1
                For Each iAtt In iNode2.ChildNodes(i).ChildNodes(0).Attributes
                    MsgBox iAtt.Name & ": " & iAtt.nodeTypedValue
                Next
            Next
        Next
    
    
        Exit Function
    
    ReadAttributes_OnError:
        MsgBox Err.Number & " - " & Err.Description
        Exit Function
    End Function
    

    0 讨论(0)
提交回复
热议问题