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

后端 未结 1 393
清酒与你
清酒与你 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

    <Donors>
        <Donor DonorID="34224" Email="tsmith@gmail.com" DonorFirstName="Tom" DonorMiddleName="" DonorLastName="Smith" DonorAddress1="2052 Main Street" DonorAddress2="" DonorCity="New York" DonorStateProv="New York" DonorPostalCode="10019" DonorPhoneHome="2125298624" DonorPhoneWork="" DonorPhoneWorkExt="" DonorPhoneMobile="" DonorEmailAlternate="">
            <PageTypes>
                  <PageType OnlinePageType="Product Purchase" /> 
            </PageTypes>
            <Transaction>
                 <Transactions TransactionID="194" CCTransactionID="-999" OrderTimeStamp="2013-05-24T07:16:37.333" OrderTotal="110.0000" /> 
            </Transaction>
            <Products>
                <Product ProductGroupName="First Pitch Tickets" ProductName="Single" ProductDescription="1 Ticket for $10" ClientCode="I000001351" ProductCount="1" TotalFees="0.0000" TotalAmount="10.0000" /> 
                <Product ProductGroupName="First Pitch Tickets" ProductName="12 Tickets" ProductDescription="12 tickets for $100" ClientCode="I000001352" ProductCount="1" TotalFees="0.0000" TotalAmount="100.0000" /> 
            </Products>
        </Donor>
    </Donors>
    

    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)
提交回复
热议问题