Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can XML be generated with Groovy MarkupBuilder that has double quotes in it?

Tags:

java

xml

groovy

Using this code:

xml = new groovy.xml.MarkupBuilder() 
xmldata = xml.Plugins(nextid: '10') {
   Target(name: 'default.auth') {
     Port(protocol: 'https') {
       mkp.yield 8080
     }
   }
}

Generates this output:

<Plugins nextid='10'>
  <Target name='default.auth'>
    <Port protocol='https'>8083</Port>
  </Target>
</Plugins>

But, is there a way to generate the output like this, with double-quotes?

<Plugins nextid="10">
  <Target name="default.auth">
    <Port protocol="https">8083</Port>
  </Target>
</Plugins>
like image 292
djangofan Avatar asked Dec 22 '22 12:12

djangofan


1 Answers

Yes, here's the documentation. MarkupBuilder.setDoubleQuotes(true)

And in case the link goes bad (copied from the above link, applies to Groovy 2.4.10)


setDoubleQuotes

public void setDoubleQuotes(boolean useDoubleQuotes)

Sets whether the builder outputs attribute values in double quotes or single quotes.

Parameters:

  • useDoubleQuotes - If this parameter is true, double quotes are used; otherwise, single quotes are.

like image 119
Jim Garrison Avatar answered Dec 24 '22 02:12

Jim Garrison