You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

从SQL Server读取HTTP XML响应:提取指定节点值求助

从SOAP XML响应中提取指定节点值

由于目标XML属于SOAP格式且带有命名空间,提取节点值时需要正确处理命名空间映射。以下是Python的实现示例:

假设HTTP响应的XML内容已存储在变量response_xml中:

import xml.etree.ElementTree as ET

# 解析XML内容
root = ET.fromstring(response_xml)

# 定义命名空间映射
namespaces = {
    'soap': 'http://schemas.xmlsoap.org/soap/envelope/',
    'ns': 'http://recharge/server'
}

# 提取RetCode节点值并去除多余空白字符
ret_code = root.find('.//ns:RetCode', namespaces).text.strip()
# 提取TaskID节点值并去除多余空白字符
task_id = root.find('.//ns:TaskID', namespaces).text.strip()

# 输出结果
print(f"RetCode: {ret_code}")
print(f"TaskID: {task_id}")

执行代码后将得到:

  • RetCode: 0
  • TaskID: U202207240001

内容的提问来源于stack exchange,提问作者Michael Marmah

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.24 20:39:15