-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProductParser.groovy
36 lines (34 loc) · 1019 Bytes
/
ProductParser.groovy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
class ProductParser {
static def parse(name, nameout) {
def fin = new File(name)
def fout = new File(nameout)
if(!fout.exists()) {
fout.createNewFile()
}
fout.write("")
def str = """
<products>"""
fin.eachLine {
def t = it.split(' ')
str += """
<product name='${t[0]}'>
<date>${t[1]}</date>
<count>${t[2]}</count>
<price>${t[3]}</price>
</product>
""".toString()
}
str += """</products>"""
fout<<'<?xml version="1.0" encoding="UTF-8"?>'
fout<<str
}
public static void main(String[] args){
if(args.length > 0 && args[0] && args[0] != '') {
def nameout = 'prods.xml'
ProductParser.parse(args[0], nameout)
new File(nameout).eachLine{println it}
} else {
println 'Point file name to parse!'
}
}
}