Question

I am having this XML,

<soapenv:Envelope xmlns:v2="http://ns1/" xmlns:ifx="http://www.somenamespace.org/IFX_150">
   <soapenv:Header></soapenv:Header>
   <soapenv:Body>
    <v2:AcctInqRq>
        <ifx:SomeTag></ifx:SomeTag>
    <v2:AcctInqRq>
   </soapenv:Body>
</soapenv:Envelope>

I am trying to copy this to a test step using xmlslurper.

def request = new XmlSlurper().parseText( holderRequest )
                              .declareNamespace( v2:'http://ns1/', 
                                                 ifx:"http://www.somenamespace.org/IFX_150")

def xmlBuilder = new StreamingMarkupBuilder()
writer = xmlBuilder.bind {
  mkp.declareNamespace(ifx:"http://www.somenamespace.org/IFX_150",v2:"http://ns1/"
  mkp.yield request
}

After copy the test step looks like this

<soapenv:Envelope>
   <soapenv:Header></soapenv:Header>
   <soapenv:Body>
    <v2:AcctInqRq xmlns:v2="http://ns1/">
        <ifx:SomeTag xmlns:ifx="http://www.somenamespace.org/IFX_150" ></ifx:SomeTag>
    <v2:AcctInqRq>
   </soapenv:Body>
</soapenv:Envelope>

Why is the namespace declaration in the not being copied as is? I want all the namespaces declared on top and not in each tag. Please help.

Was it helpful?

Solution

You can turn off namespace support, and just pass them through as-is?

def request = new XmlSlurper( false, false ).parseText( holderRequest )
def output = new StreamingMarkupBuilder().bind {
  mkp.yield request
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top