遍历xml并使用vbscript获取所有子节点值

时间:2020-02-24 21:42:18

标签: xml parsing vbscript

我对VB脚本还很陌生,它试图通过解析xml响应中的每个属性块来读取xml。我的确看到了其他带有示例的帖子,但在这里找不到任何直接帮助解决该问题的方法。下面是我开始的代码,但请确保我可能在这里没有正确的路径。

Dim xmlDoc, objNodeList, plot

Set xmlDoc = CreateObject("Msxml2.DOMDocument")
xmlDoc.load("C:\TestData\Blhdr_sampleresp_test.xml")
Set objNodeList = xmlDoc.getElementsByTagName("Blhd_cust_head_detail")
If objNodeList.length > 0 then
For each x in objNodeList
plot=x.Text
msgbox plot
Next
Else
msgbox "Node not found."
End If

这是我的示例XML:

<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
   <soap:Body>
      <GetBillCustResponse xmlns="http://www.test.com/test3">
         <GetBillCustResult>
            <Blhd_request>
               <User_id>User1</User_id>
               <Origin_sys_nm>TEST</Origin_sys_nm>
               <Operation_nm>GETCUST</Operation_nm>
               <Blhd_rqst_data>
                  <Blhd_cust_acct_nb>0755970501</Blhd_cust_acct_nb>
                  <Blhd_cust_start_dt>2019-09-10</Blhd_cust_start_dt>
                  <Blhd_cust_stop_dt>2019-12-12</Blhd_cust_stop_dt>
               </Blhd_rqst_data>
            </Blhd_request>
            <Blhd_return>
               <Response_cd>20000</Response_cd>
               <Response_desc_tx>SUCCESS</Response_desc_tx>
               <Err_cnt>0</Err_cnt>
               <Error_details/>
               <Blhd_resp_data>
                  <Blhd_cust_head_cnt>2</Blhd_cust_head_cnt>
                  <Blhd_cust_head_detail>
                     <Blhd_cust_head_nb>102</Blhd_cust_head_nb>
                     <Blhd_cust_dt>2019-11-11</Blhd_cust_dt>
                  </Blhd_cust_head_detail>
                  <Blhd_cust_head_detail>
                     <Blhd_cust_head_nb>104</Blhd_cust_head_nb>
                     <Blhd_cust_dt>2019-12-12</Blhd_cust_dt>
                  </Blhd_cust_head_detail>
               </Blhd_resp_data>
            </Blhd_return>
         </GetBillCustResult>
      </GetBillCustResponse>
   </soap:Body>
</soap:Envelope>

0 个答案:

没有答案