如何避免外部范围值干扰使用 MarkupBuilder?
我的 xml 中需要一个名为 file 的元素,但是 gradle 项目有一个名为 file 的属性,该属性被调用。解决这个问题的最佳方法是什么?
import groovy.xml.MarkupBuilder
task test {
def writer = new StringWriter()
def xml = new MarkupBuilder(writer)
xml.elem1(test: 'fest') {
elem2(a: 'b')
file(c: 'd')
elem4(e: 'f')
}
println(writer)
}
I need an element named file in my xml, however the gradle project have a property named file which is called instead. What is the best way around this?
import groovy.xml.MarkupBuilder
task test {
def writer = new StringWriter()
def xml = new MarkupBuilder(writer)
xml.elem1(test: 'fest') {
elem2(a: 'b')
file(c: 'd')
elem4(e: 'f')
}
println(writer)
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您应该能够执行以下操作:
You should be able to do:
您应该能够使用“委托”变量,该变量在每个 XML 元素的代码块中自动可用。
例如:
You should be able to use the 'delegate' variable, which is automatically made available within each XML element's code block.
For example: