【问题标题】:How cna I parse an XML string and retrieve specific nodes?如何解析 XML 字符串并检索特定节点?
【发布时间】:2021-01-13 19:23:39
【问题描述】:

我有这个变量 decodedRequest 作为字符串,它的值是下面的 XML。我假设我仍然需要将此字符串转换为 XML 格式。以及如何获取 标记以及 标记内的值?

<?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>

【问题讨论】:

标签: asp.net .net xml vb.net


【解决方案1】:

所以这行得通:

    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

【讨论】:

  • 也就是说,只加载XML字符串,不需要转换。这个问题还不清楚——如果你问how can I parse an XML string and retrieve specific nodes,人们会指出显示如何使用 XmlDocument 或 LINQ to XML 的重复项。
猜你喜欢
  • 2012-01-14
  • 2012-07-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多