加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

Groovy --> XML

发布时间:2020-12-14 16:55:55 所属栏目:大数据 来源:网络整理
导读:Groovy ---- XML import?? groovy.xml.MarkupBuilder def out? =?? new? StringWriter() def xml? =?? new? MarkupBuilder(out) def priceList? =? [ ' 1.64 ',? ' 2.45',? ' 3.85 ',? ' 4.64 ',? ' 5.23 ' ] xml.product { ??? name(type: " 商品名 ","汽水

Groovy ----> XML

import?? groovy.xml.MarkupBuilder

def out? =?? new? StringWriter()
def xml? =?? new? MarkupBuilder(out)

def priceList? =? [ ' 1.64 ',? ' 2.45',? ' 3.85 ',? ' 4.64 ',? ' 5.23 ' ]

xml.product {
??? name(type: " 商品名 ","汽水-小七")
??? disc "300ML"
??? price(num: priceList.size()) {
??????? for (p in priceList) {
??????????? price p
??????? }
??? }
}

println out.toString()

#############结果Result##############
<product>
? <name type=' 商品名 '>汽水-小七</name>
? <disc>300ML</disc>
? <price num='5'>
??? <price> 1.64 </price>
??? <price> 2.45</price>
??? <price> 3.85 </price>
??? <price> 4.64 </price>
??? <price> 5.23 </price>
? </price>
</product>

?

?

如果你要在<product>里面加入ID 可以这样做 xml.product(id:i)

?

import?? groovy.xml.MarkupBuilder

def out? =?? new? StringWriter()
def xml? =?? new? MarkupBuilder(out)

def priceList? =? [ ' 1.64 ',? ' 5.23 ' ]
println? priceList.getClass().name
def i = '12 cans 7up'

xml.product(id:i) {
??? name(type: " soda ","小七")
??? disc "300ML"
??? price(num: priceList.size()) {
??????? for (p in priceList) {
??????????? price p
??????? }
??? }
}

println out.toString()

############################Result##########

<product id='12 cans 7up'>
? <name type=' soda '>小七</name>
? <disc>300ML</disc>
? <price num='5'>
??? <price> 1.64 </price>
??? <price> 2.45</price>
??? <price> 3.85 </price>
??? <price> 4.64 </price>
??? <price> 5.23 </price>
? </price>
</product>

?

?

Groovy --------->/**?* Created by IntelliJ IDEA.?* User: James?* Date: Mar 18,2009?* Time: 4:05:08 PM?* To change this template use File | Settings | File Templates.?*/import? groovy.xml.MarkupBuilderdef out? =?? new? StringWriter()def html? =?? new? MarkupBuilder(out)//html.'${html}'html.html {??? body {??????? font(color:'red',size:6) {??????????? b "Hello,world!"??????? }??? }}println out.toString()#############结果Result##############<html>? <body>??? <font color='red' size='6'>????? <b>Hello,world!</b>??? </font>? </body></html>

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读