0

We are trying to parse the below response and get the value "123456" from "result" tag using VBA Code but we are not getting anything:

Response Received:

------=_Part_119884_965967558.1620391101235
Content-Type: application/xop+xml;charset=utf-8;type="text/xml"
Content-Transfer-Encoding: 8bit
Content-ID: <e119e24d-e0b6-4ceb-a00a-dd094ef91ef7>

<?xml version="1.0" encoding="utf-8" ?>
<env:Envelope
    xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"
    xmlns:wsa="http://www.w3.org/2005/08/addressing">
    <env:Header>
        <wsa:Action>http://xxxx</wsa:Action>
        <wsa:MessageID>urn:uuid:xxxx</wsa:MessageID>
    </env:Header>
    <env:Body>
        <ns0:uploadFileResponse
            xmlns:ns0="http://xxxx">
            <result
                xmlns="http://xxxx">123456
            </result>
        </ns0:uploadFileResponse>
    </env:Body>
</env:Envelope>

------=_Part_119884_965967558.1620391101235--

VBA Code:

    Dim xmldoc As Object
    Dim xmlnode As Object
    Set xmldoc = CreateObject("Microsoft.XMLDOM")
    xmldoc.SetProperty "SelectionLanguage", "XPath"
    xmldoc.async = False
    xmldoc.LoadXML .ResponseText
    For Each xmlnode In xmldoc.SelectNodes("//*[contains(name(),'result')]")
        Debug.Print "Document ID: "; xmlnode.text
    Next

Please help

1 Answer 1

1

You need to clean-up the response.

    Dim xmldoc As Object
    Dim xmlnode As Object
    Set xmldoc = CreateObject("Microsoft.XMLDOM")
    xmldoc.SetProperty "SelectionLanguage", "XPath"
    xmldoc.async = False
    
    Dim xml As String
    xml = .ResponseText
    xml = Mid(xml, InStr(1, xml, "<?xml "))
    xml = Left(xml, InStr(1, xml, "Envelope>") + Len("Envelope"))

    If xmldoc.LoadXML(xml) = True Then
        For Each xmlnode In xmldoc.SelectNodes("//*[contains(name(),'result')]")
            Debug.Print "Document ID: "; xmlnode.Text
        Next
    Else
        MsgBox "XML failed to load", vbCritical
    End If
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.