1

我已经编写了用于请求 Web 服务的 xml 代码,我得到了正确的响应,例如:

<?xml version="1.0" encoding="utf-8"?>
<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>
    <getOrderFileResponse xmlns="http://www.edocbuilder.com/">
      <getOrderFileResult>**string**</getOrderFileResult>
    </getOrderFileResponse>
  </soap:Body>
</soap:Envelope>

我只想要这个响应中的字符串

你能帮帮我吗?

4

1 回答 1

2

我可以提供这个函数来轻松提取经典 ASP 中的值:

function findStringBetween(s_string, s_pre, s_post, n_options)
  ' n_options:
  '  1: IGNORE case in the search
  dim a, b
  ' init
  findStringBetween = ""
  ' find pre-word
  a = instr(1, s_string, s_pre, n_options)
  if a>0 then
    a = a + len(s_pre)
    b = instr(a, s_string, s_post, n_options)
    if b>0 and not (s_post = "") then
      findStringBetween = mid(s_string, a, b-a)
    else
      findStringBetween = mid(s_string, a)
    end if
  end if
end function

将其包含在您的代码中,然后您可以像这样使用它:

dim my_value
my_value = findStringBetween(s_soap_response, "<getOrderFileResult>", "</getOrderFileResult>", 0)
于 2012-05-15T13:17:10.130 回答