xml - 是否可以操纵肥皂信封元素?
问题描述
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:api="http://someuri/">
<soapenv:Header/>
<soap:Body>
<Element>
///
</Element>
<Element>
///
</Element>
</soap:Body>
</soap:Envelope>
你好
我需要使用 GroovyScript 将信封元素中 [xmlns:api="http://someuri/"] 中的 uri 更改为“someotheruri”。
我搜索了几个小时如何使用 xmlslurper、xmlparser,每个节点都可以轻松更改。但我需要更改根元素中的这个命名空间。
def source = new File("test.xml").text
def root = new XmlSlurper(false, false).parseText(source)
println(root.lookupNamespace("api"))
它给了我作为字符串的uri,但不是它的节点。我错过了什么吗?
真的很晚了,现在我最后的希望就是在这里问。
提前致谢!
解决方案
项目文件是一个 XML。您可以replaceAll()
在 SoapUI 之外对项目文件执行以下操作:
def projectFileA = new File('/path/to/your/soapui-project.xml')
def projectFileB = projectFileA.text.replaceAll('xmlns:api="http://someuri/"', 'xmlns:api="http://someotheruri/"')
projectfileA.text = projectfileB
推荐阅读
- python - 需要 Python/Spark 中的逆误差函数代码
- c++ - 在 C++ 中使用它之前从 std::aligned_storage 派生指针是否安全?
- python - Gspread 异常 DECRYPTION_FAILED_OR_BAD_RECORD_MAC
- sql - 将随机日期生成为系列
- linux - 无法从 Azure 虚拟机启动到 packages.cloud.google.com:443 的连接
- elasticsearch - Elasticsearch 如何设置高亮匹配的查询词
- amazon-web-services - AWS.config 和 AWSConfig.config 有什么不同(AWS cognito)
- lua - 如何使用特使前端代理仅重定向一个域而不是全部重定向到 401
- google-cloud-pubsub - Debezium 服务器并启用 Jaeger 跟踪
- python - python有没有办法检测乱码或损坏的字符?