简体   繁体   English

可以使用带有双引号的Groovy MarkupBuilder生成XML吗?

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

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>

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) 如果链接变坏(从上面的链接复制,适用于Groovy 2.4.10)


setDoubleQuotes 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; useDoubleQuotes - 如果此参数为true,则使用双引号; otherwise, single quotes are. 否则,单引号是。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM