cancel
Showing results for 
Search instead for 
Did you mean: 

SAP Cloud integration - Set namespace groovy script

Cristian
Participant
0 Kudos

Hi experts,

We have a groovy script for mapping a JSON to XML.

For creating the XML we are using roovy.xml.MarkupBuilder.

// Define XML builder

def writer = new StringWriter()

def builder = new MarkupBuilder(writer)

builder.mkp.xmlDeclaration(version: "1.0", encoding: "utf-8")

What is the way to set up the namespace of the target XML?

Many thanks,

C.

View Entire Topic
MortenWittrock
Active Contributor

Hi Cristian

Namespace declarations can be added similar to how you add attributes. So something like this:

def sw = new StringWriter()
def builder = new MarkupBuilder(sw)

builder.'n:document'('xmlns:n': 'http://example.org/my/namespace') {
'n:message'('Hello, world!')
}

Regards,

Morten

Cristian
Participant

Many thanks! Issue sorted!