English 中文(简体)
如何避免使用MarkupBuilder的外观价值?
原标题:How to avoid outer-scope values messing with using the MarkupBuilder?

我需要在我的xml中找到一个点名档案,然而,梯度项目有一份被称作取名的财产档案。 这方面的最佳途径是什么?

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)
}
最佳回答

你们应当能够做到:

xml.file( c:  d  )
问题回答

你们应当能够使用授权变量,自动在《反洗钱法》各组成部分的代码范围内提供。

例如:

import groovy.xml.MarkupBuilder

task test {
  def writer = new StringWriter()
  def xml = new MarkupBuilder(writer)
  xml.elem1(test:  fest ) {
    elem2(a:  b )
    delegate.file(c:  d )
    elem4(e:  f )
  }
  println(writer)
}




相关问题
Groovy - how to exit each loop?

I m new to Grails/Groovy and am trying to find a node in a an xml file; I ve figured out how to iterate over all of them, but I want to exit the loop when the target node is found. I ve read that ...

Eclipse Spring Builder set properties with Groovy beans

I typically use groovy to construct simple bean but the Spring IDE plugin to eclipse fails to build when I try to set a property that is generated by groovy without an explicit setter. For example, ...

How can I get this snippet to work?

I d like to port a little piece of code from Ruby to Groovy, and I m stuck at this: def given(array,closure) { closure.delegate = array closure() } given([1,2,3,4]) { findAll { it > 4} ...

Changing the value in a map in Groovy

This is about a very basic program I m writing in Groovy. I have defined a map inside a method: def addItem() { print("Enter the item name: ") def itemName = reader.readLine() print(...

Is functional Clojure or imperative Groovy more readable?

OK, no cheating now. No, really, take a minute or two and try this out. What does "positions" do? Edit: simplified according to cgrand s suggestion. (defn redux [[current next] flag] [(if flag ...

热门标签