Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用groovy向xml添加xsi命名空间前缀_Xml_Groovy_Soapui - Fatal编程技术网

如何使用groovy向xml添加xsi命名空间前缀

如何使用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:/

我尝试使用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://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)

您可以在线快速尝试

您是否尝试过给定的解决方案以查看其是否有帮助?您是否尝试过给定的解决方案以查看其是否有帮助?