【发布时间】:2019-07-29 04:33:59
【问题描述】:
如果有任何帮助,我将不胜感激。我需要解析 XML SOAP 文档,但总是得到相同的结果 -> 没有标签的纯文本。如何从 XML 获取特定/单个标签 (f.e. vatNumber) 值?谢谢。
这是我的 VBA 代码:
ObjHTTP.Open "Post", sURL, False
ObjHTTP.setRequestHeader "Content-Type", "text/xml"
ObjHTTP.send (sEnv)
'parse xml response - output
Dim responseDocument As MSXML2.DOMDocument60
Set responseDocument = New MSXML2.DOMDocument60
responseDocument.async = False
responseDocument.validateOnParse = False
responseDocument.SetProperty "SelectionNamespaces", " xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'"
responseDocument.LoadXML (ObjHTTP.responseText)
If responseDocument.parseError.reason <> "" Then
MsgBox m_objDOMPeople.parseError.reason
Exit Sub
End If
MsgBox responseDocument.SelectNodes("/soap:Envelope/soap:Body")(0).Text
Set ObjHTTP = Nothing
Set xmldoc = Nothing
这是 XML SOAP 输入:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<checkVatResponse xmlns="urn:ec.europa.eu:taxud:vies:services:checkVat:types">
<countryCode>SK</countryCode>
<vatNumber>204566287588</vatNumber>
<requestDate>2015-04-07+01:00</requestDate>
<valid>true</valid>
<name>Company k. s.</name>
<address>Some Address</address>
</checkVatResponse>
</soap:Body>
</soap:Envelope>
【问题讨论】:
标签: xml vba soap web-scraping