[英]How cna I parse an XML string and retrieve specific nodes?
我將此變量decodedRequest作為字符串,它具有下面的 XML 值。 我假設我仍然需要將此字符串轉換為 XML 格式。 以及如何獲取 <request_id> 和 <response_id> 標簽以及 <response_message> 標簽中的值?
<?xml version="1.0" encoding="UTF-8"?>
<ServiceResponseWPF xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<application>
<merchantid>0000011111</merchantid>
<request_id>456789</request_id>
<response_id>ASD123</response_id>
<timestamp>2020-09-23T16:51:47.000000+08:00</timestamp>
<rebill_id />
<signature>a246521e3a97bc80502322513434c24d475c4966fe8931b45</signature>
<ptype>CC</ptype>
</application>
<responseStatus>
<response_code>GR00</response_code>
<response_message>Successful</response_message>
<response_advise>Approved</response_advise>
<processor_response_id>30000</processor_response_id>
<processor_response_authcode>50001</processor_response_authcode>
</responseStatus>
<sub_data />
<transactionHistory>
<transaction />
</transactionHistory>
</ServiceResponseWPF>
所以這有效:
Dim x As XmlDocument = New XmlDocument()
x.LoadXml(decodedRequest)
Dim req_id As String = x.SelectSingleNode("/ServiceResponseWPF/application/request_id").InnerText
Dim res_code As String = x.SelectSingleNode("/ServiceResponseWPF/responseStatus/response_code").InnerText
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.