I am trying to connect one MS Access database to a SOAP service.
I was able to connect to the service, retrieve the XML, but I can't read a node value.
This is my code (I replaced some confidential things with ++++++
):
Option Compare Database
Private Sub lanzar_XML_Click()
Dim sUrl As String
Dim sEnv As String
Dim xmlhtp As MSXML2.XMLHTTP60
Dim xmlDoc As MSXML2.DOMDocument60
Dim limpiartexto As String
Dim Valoresxml As MSXML2.IXMLDOMNode
sUrl = "++++++"
sEnv = "<soapenv:Envelope xmlns:soapenv=""http://schemas.xmlsoap.org/soap/envelope/"" xmlns:hai=""++++++"">"
sEnv = sEnv & " <soapenv:Header/>"
sEnv = sEnv & " <soapenv:Body>"
sEnv = sEnv & " <hai:QuerySRInfo>"
sEnv = sEnv & " <SRNum>EUES160624000378</SRNum>"
sEnv = sEnv & " <ServiceCenterId>++++++</ServiceCenterId>"
sEnv = sEnv & " <ServiceCenterPW>++++++</ServiceCenterPW>"
sEnv = sEnv & " </hai:QuerySRInfo>"
sEnv = sEnv & " </soapenv:Body>"
sEnv = sEnv & "</soapenv:Envelope>"
Set xmlhtp = New MSXML2.XMLHTTP60
With xmlhtp
.Open "POST", sUrl, False
.setRequestHeader "Content-Type", "text/xml;charset=UTF-8"
' .setRequestHeader "SOAPAction:", "rpc/http://www.++++++.com/:QuerySRInfo"
.setRequestHeader "Content-Length", "Lenght"
.send sEnv
Set xmlDoc = New MSXML2.DOMDocument60
xmlDoc.loadXML .responseText
limpiartexto = xmlDoc.XML
limpiartexto = Right(limpiartexto, Len(limpiartexto) - 327)
limpiartexto = Left(limpiartexto, Len(limpiartexto) - 64)
Debug.Print limpiartexto
End With
xmlDoc.loadXML limpiartexto
For Each Valoresxml In xmlDoc.getElementsByTagName("ServiceRequests")
Me.MobilePhone = Valoresxml.selectNodes("MobilePhone")(0).Text
MsgBox Valoresxml.selectNodes("MobilePhone")(0).Text
Next
End Sub
I believe my problem is with the format of the XML that is retrieved, instead of a well structured XML, it is just a one-liner containing all nodes.
My debug.print
returns:
<ServiceRequests><ServiceRequest xmlns="http://www.siebel.com/xml/SPI%20HET%20ASC%20Query%20Service%20Request"><SrNumber>EUES160624000378</SrNumber><CustomerName>++++++</CustomerName><FirstName>++++++</FirstName><LastName>++++++</LastName><ContactEmail></ContactEmail><MobilePhone>600600600</MobilePhone><HomePhone></HomePhone><WorkPhone></WorkPhone><CustomerGender></CustomerGender><CustomerCoutnry>Spain</CustomerCoutnry><CustomerState></CustomerState><SubmissionTime></SubmissionTime><OfflineSubmissionTime></OfflineSubmissionTime></ServiceRequest></ServiceRequests>
...but I think it should return:
<ServiceRequests>
<ServiceRequest xmlns="http://www.siebel.com/xml/SPI%20HET%20ASC%20Query%20Service%20Request">
<SrNumber>EUES160624000378</SrNumber>
<CustomerName>++++++</CustomerName>
<FirstName>++++++</FirstName>
<LastName>++++++</LastName>
<ContactEmail></ContactEmail>
<MobilePhone>600600600</MobilePhone>
<HomePhone></HomePhone>
<WorkPhone></WorkPhone>
<CustomerGender></CustomerGender>
<CustomerCoutnry>Spain</CustomerCoutnry>
<CustomerState></CustomerState>
<SubmissionTime></SubmissionTime>
<OfflineSubmissionTime></OfflineSubmissionTime>
</ServiceRequest>
</ServiceRequests>
How can I deal with that?
Note: when I use soapui
, the returned XML looks fine.