如何使用groovy向xml添加xsi命名空间前缀
我尝试使用groovySoapUI创建以下XML 预期的XML如何使用groovy向xml添加xsi命名空间前缀,xml,groovy,soapui,Xml,Groovy,Soapui,我尝试使用groovySoapUI创建以下XML 预期的XML <S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"> <S:Body> <ns2:save xmlns:ns2="http://service.generic.abc.it"> <arg1 xsi:type="ns4:ContractGroup" xmlns:ns4="http:/
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Body>
<ns2:save xmlns:ns2="http://service.generic.abc.it">
<arg1 xsi:type="ns4:ContractGroup" xmlns:ns4="http://generic.abc.it" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<discounts xsi:type="ns4:DiscountPrice"></discounts>
</arg1>
</ns2:save>
</S:Body>
</S:Envelope>
给你,评论在线
import groovy.xml.StreamingMarkupBuilder
import groovy.xml.XmlUtil
def builder = new StreamingMarkupBuilder()
builder.encoding = 'UTF-8'
def xml = builder.bind {
mkp.xmlDeclaration()
//Declare the namespaces
namespaces << [ S:'http://schemas.xmlsoap.org/soap/envelope/',
xsi: 'http://www.w3.org/2001/XMLSchema-instance',
ns2: 'http://service.generic.abc.it',
ns4: 'http://generic.abc.it']
//You can see building the xml as you wanted it
S.Envelope {
S.Body {
ns2.save {
arg1('xsi.type': 'ns4:ContractGroup' ){
discounts('xsi.type': 'ns4:DiscountPrice')
}
}
}
}
}
println XmlUtil.serialize(xml)
您可以在线快速试用给您,在线评论
import groovy.xml.StreamingMarkupBuilder
import groovy.xml.XmlUtil
def builder = new StreamingMarkupBuilder()
builder.encoding = 'UTF-8'
def xml = builder.bind {
mkp.xmlDeclaration()
//Declare the namespaces
namespaces << [ S:'http://schemas.xmlsoap.org/soap/envelope/',
xsi: 'http://www.w3.org/2001/XMLSchema-instance',
ns2: 'http://service.generic.abc.it',
ns4: 'http://generic.abc.it']
//You can see building the xml as you wanted it
S.Envelope {
S.Body {
ns2.save {
arg1('xsi.type': 'ns4:ContractGroup' ){
discounts('xsi.type': 'ns4:DiscountPrice')
}
}
}
}
}
println XmlUtil.serialize(xml)
您可以在线快速尝试您是否尝试过给定的解决方案以查看其是否有帮助?您是否尝试过给定的解决方案以查看其是否有帮助?