创建带有“信封”的 groovy xml - 在 xml 结构中间添加节点
(抱歉这个奇怪的标题...)
我想使用 groovy 构建器系统来创建一个 xml。
我的问题是我想要某种信封,用户不必关心。
一个例子:
def builder = new groovy.xml.MarkupBuilder()
builder.foo() {
bar('hello')
}
这应该创建让我们说
<Something id:'123'>
<AnyInfo>
<foo>
<bar>hello</bar>
</foo>
</AnyInfo>
</Something>
后台有一个 xml 结构,用户可以在其中的预定义节点(在示例“AnyInfo”中)添加他的 xml 结构
构建器必须是什么样子,我可以使用标记构建器(或任何其他构建器)在信封中间的某个位置添加节点吗?
我希望这是可以理解的?!
谢谢 马蒂
(sorry for the weird title...)
I want to use the groovy builder system to create a xml.
My problem is that i want to have some kind of envelop around, which the user dont has to care about.
An example:
def builder = new groovy.xml.MarkupBuilder()
builder.foo() {
bar('hello')
}
this should create lets say
<Something id:'123'>
<AnyInfo>
<foo>
<bar>hello</bar>
</foo>
</AnyInfo>
</Something>
so that there is a xml structure in the background in which the user can add his xml structure at a predefined node (in the example 'AnyInfo')
How does the builder has to look like, that I can add nodes with the markupbuilder (or any other builder) somewhere in the middle of the envelop ?
I hope this was somehow understandable ?!
THANKS
Marty
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用闭包轻松地做到这一点。创建一个闭包来创建包装器。然后,您可以动态地提交创建实际内容的闭包。示例:
由此创建的结果是您正在寻找的示例 XML。
You can do this easily with closures. Create a closure to create the wrapper. You can then dynamically hand in your closure that creates the actual content. Example:
The result created by this is the sample XML you were looking for.