Excelマクロと私の非常に最初のベンチャーを返していない、私は Webサービスの応答を解析するためのコードを書いていると私は、Excelで 個々のセルにタグ値を更新したいと思います。VBA ExcelのマクロSELECTSINGLENODEは何も
には、以下のI「は、コードの私のXMLの抜粋(巨大なWebサービス応答)
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"/>
<soap:Body>
<bm:getTransactionResponse xmlns:bm="http://xmlns.oracle.com/XXXCLD/commerce/ZZZYYY_PPP_1">
<bm:status>
<bm:success>true</bm:success>
<bm:message>Wed Apr 06 09:04:32 UTC 2016 - Successfully processed API for test1</bm:message>
</bm:status>
<bm:transaction>
<bm:category>data</bm:category>
<bm:action>add</bm:action>
<bm:id>1111</bm:id>
<bm:process_var_name>xvgfdr</bm:process_var_name>
<bm:buyer_company_name>test1</bm:buyer_company_name>
<bm:supplier_company_name>test1</bm:supplier_company_name>
<bm:step_var_name>waitingForInternalApproval</bm:step_var_name>
<bm:last_document_number>2</bm:last_document_number>
<bm:date_added>2016-04-04 12:14:57</bm:date_added>
<bm:date_modified>2016-04-06 09:04:18</bm:date_modified>
<bm:data_xml>
<bm:transaction bm:bs_id="11111" bm:buyer_company_name="test1" bm:buyer_user_name="someone" bm:currency_pref="GBP" bm:data_type="0" bm:document_name="Transaction" bm:document_number="1" bm:document_var_name="transaction" bm:process_var_name="XXX_1" bm:supplier_company_name="test1">
<bm:_document_number>1</bm:_document_number>
<bm:createdBy_t>SomeOne</bm:createdBy_t>
<bm:_price_book_var_name>_default</bm:_price_book_var_name>
<bm:createdDate_t>2016-04-04 00:00:00</bm:createdDate_t>
<bm:currency_t>INR</bm:currency_t>
<bm:_customer_t_first_name/>
<bm:_customer_t_last_name/>
<bm:_customer_t_company_name>Test Account</bm:_customer_t_company_name>
私はタグの下<bm:_customer_t_company_name>
の値を取得しようとしていますされています使用しています。
Sub Button1_Click()
'Set and instantiate our working objects
Dim Req As Object
Dim sEnv As String
Dim Resp As New MSXML2.DOMDocument60
Set Req = CreateObject("MSXML2.XMLHTTP")
Set Resp = CreateObject("MSXML2.DOMDocument.6.0")
With Req
.Open "Post", "https://XXXX.com/", False
Dim Pwd As String
Pwd = Range("D8").Value
Dim QuoteId As String
QuoteId = Range("D9").Value
' SOAP envelope for submission to the Web Service
sEnv = sEnv & "<soapenv:Envelope xmlns:soapenv=""http://schemas.xmlsoap.org/soap/envelope/"">"
sEnv = sEnv & " <soapenv:Header>"
sEnv = sEnv & " <wsse:Security xmlns:wsse=""http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"" xmlns:wsu=""http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"">"
sEnv = sEnv & " <wsse:UsernameToken wsu:Id=""UsernameToken-2"">"
sEnv = sEnv & " <wsse:Username>" & Range("D7").Value & "</wsse:Username>"
sEnv = sEnv & " <wsse:Password Type=""http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText"">" & Pwd & "</wsse:Password>"
sEnv = sEnv & " </wsse:UsernameToken>"
sEnv = sEnv & " </wsse:Security>"
sEnv = sEnv & " </soapenv:Header>"
sEnv = sEnv & " <soapenv:Body>"
sEnv = sEnv & " <bm:getTransaction>"
sEnv = sEnv & " <bm:transaction>"
sEnv = sEnv & " <bm:id>" & Range("D9").Value & "</bm:id>"
sEnv = sEnv & " </bm:transaction>"
sEnv = sEnv & " </bm:getTransaction>"
sEnv = sEnv & " </soapenv:Body>"
sEnv = sEnv & "</soapenv:Envelope>"
' Send SOAP Request
.send (sEnv)
Resp.LoadXML Req.responseText
End With
If Resp Is Nothing Then
MsgBox "No XML"
End If
With Resp
.setProperty "SelectionNamespaces", "xmlns:bm=""http://xmlns.oracle.com/XXXCLD/commerce/ZZZYYY_PPP_1"" xmlns:soap=""http://schemas.xmlsoap.org/soap/envelope/"""
Dim strName As String
If .SelectSingleNode("//bm:_customer_t_company_name") Is Nothing Then
MsgBox "No Node"
End If
strName = .SelectSingleNode("//bm:_customer_t_company_name").Text
MsgBox strName
End With
'clean up code
Set Req = Nothing
Set Resp = Nothing
Range("A1").Value = "DONE"
End Sub
.SelectSingleNode( "//石鹸:ボディ")が正常に動作します。 .SelectSingleNode( "// bm:_customer_t_company_name")は、コードをテストするときに常にNothingを返します。したがって、
.SelectSingleNode( "// bm:getTransactionResponse")は何も返しません。
私が間違っていることを教えてもらえますか?ここで
これはテストしていませんが、これが役立つかもしれません。 xmlnamespacemanagerに名前空間を追加し、それをex:iに割り当てられた名前空間に渡します。次に、abcに割り当てられた名前空間.SelectSingleNode( "// abc:bm:_customer_t_company_name" –
クイックレスポンスのKarthikに感謝。 以下のコードを実行時エラー。 .setProperty "SelectionNamespaces"、 "xmlns:abc =" "" http://xmlns.oracle.com/XXXCLD/commerce/ZZZYYY_PPP_1 "" xmlns:soap = "" http://schemas.xmlsoap.org/soap /封筒/ "" "文字列 として 薄暗いSTRNAME .SelectSingleNode場合( "// ABC:BM:_customer_t_company_name")は、ノードなし次に MsgBoxに何もありません "" もし STRNAME = .SelectSingleNode終了(" // ABC:BM :_customer_t_company_name ")。テキスト 予想されるトークン 'EOF' ND ':' /ABC:BM - >:<-_ customer_t_company_name – user5185291