views:

260

answers:

1

How can i create an attribute with a namespace? To get the following output?

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

This is how i do it yet:

catalogItem( type:"specialItem");

But this generates the attribute without namespace, so its invalid

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

so i'm searching for something like this (with initialized xsi for ns):

catalogItem( xsi.type:"specialItem");

Thank you in advance

chrsk

+1  A: 

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'&gt;
  <car name='HSV Maloo' make='Holden' year='2006'>
    <country>Australia</country>
    <record type='speed'> Truck with speed of 271kph</record>
  </car>
</rec:records>

More here.

This works very fine, thank you. Sorry i didn't found this article of groovy codehaus.
codedevour