首页 > 解决方案 > 是否可以操纵肥皂信封元素?

问题描述

<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,但不是它的节点。我错过了什么吗?

真的很晚了,现在我最后的希望就是在这里问。

提前致谢!

标签: xmlsoapgroovysoapui

解决方案


项目文件是一个 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

推荐阅读