How to create namespace attribute using groovy xml builder

How do I create an attribute with a namespace? To get the next output?

<tns:catalogItem xsi:type="specialItem" />

      

This is how I do it:

catalogItem( type:"specialItem");

      

But this generates an attribute without namespace, so its invalid

<tns:catalogItem type="tns:specialItem" />

      

so I'm looking for something like this (with an initialized xsi for ns):

catalogItem( xsi.type:"specialItem");

      

Thank you in advance

chrsk

+2


source to share


1 answer


This Groovy code:

def xml = new MarkupBuilder(writer)
xml.'rec:records'('xmlns:rec': 'http://groovy.codehaus.org') {
  car(name:'HSV Maloo', make:'Holden', year:2006) {
    country('Australia')
    record(type:'speed', ' Truck with speed of 271kph')
  }
}

      

results in this XML:



<rec:records xmlns:rec='http://groovy.codehaus.org'>
  <car name='HSV Maloo' make='Holden' year='2006'>
    <country>Australia</country>
    <record type='speed'> Truck with speed of 271kph</record>
  </car>
</rec:records>

      

More details here .

+3


source







All Articles