开发者

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

Using this code:

xml = new groovy.xml.MarkupBuilder() 
xml开发者_JS百科data = 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>


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜