Question

I am using StreamingMarkupBuilder to produce XML and I need to have a tag. Unfortunately I get exception :

Caught: java.lang.ClassCastException: java.util.LinkedHashMap cannot be cast to java.lang.Class

any ideas how I can create such tag?

import groovy.xml.StreamingMarkupBuilder
import org.custommonkey.xmlunit.*
import groovy.xml.XmlUtil

def xml = new StreamingMarkupBuilder().bind{
'use'(name:'Name', type:'type', year:2006) {
  desc('desc')
} 

} 

println xml.toString()
Était-ce utile?

La solution

You have to use the builder as a prefix to the keyword use, ie:

def xml = new StreamingMarkupBuilder().bind { smb ->
  smb.use( name:'Name', type:'type', year:2006 ) {
    desc( 'desc' )
  } 
} 

println xml.toString()

prints:

<use name='Name' type='type' year='2006'><desc>desc</desc></use>
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top