-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprocess-parser.go
More file actions
146 lines (99 loc) · 2.39 KB
/
process-parser.go
File metadata and controls
146 lines (99 loc) · 2.39 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
package main
import (
"fmt"
"encoding/xml"
"os"
"io/ioutil"
)
type Beans struct {
BeanList []Bean `xml:"bean"`
}
type Bean struct {
Id string `xml:"id,attr"`
Class string `xml:"class,attr"`
Singleton string `xml:"singleton,attr"`
Description string `xml:"description"`
EntryList []Entry `xml:"property>map>entry"`
}
type Entry struct {
Key string `xml:"key,attr"`
Value string `xml:"value,attr"`
}
type P_file struct {
total int
beans Objects
}
type Objects struct {
object map[string]map[string]string
}
func unpackElements(packed Beans) Objects {
var objects Objects
objects.object = make(map[string]map[string]string)
for _,v := range packed.BeanList {
objects.object[v.Id] = make(map[string]string)
objects.object[v.Id]["description"] = v.Description
objects.object[v.Id]["class"] = v.Class
objects.object[v.Id]["singleton"] = v.Singleton
for _,c := range v.EntryList {
objects.object[v.Id][c.Key] = c.Value
}
}
return objects
}
func packElements(unpacked P_file) Beans {
var packedfile Beans
for k,v := range unpacked.beans.object {
var bean Bean
bean.Id = k
bean.Description = v["description"]
bean.Class = v["class"]
bean.Singleton = v["singleton"]
for key,val := range v {
if key != "class" && key != "singleton" && key != "description" {
var e Entry
e.Key = key
e.Value = val
bean.EntryList = append(bean.EntryList, e)
}
}
packedfile.BeanList = append(packedfile.BeanList, bean)
}
return packedfile
}
func main() {
xmlfile, err := os.Open("/Users/willemveerman/Documents/FSM/process-conf.xml")
if err != nil {
fmt.Println(err)
} else {
fmt.Println("Successfully opened XML file.")
}
byteValue, _ := ioutil.ReadAll(xmlfile)
var b Beans
xml.Unmarshal(byteValue, &b)
c := b
xml.Marshal(c)
objects := unpackElements(b)
ff := b.BeanList[0].Description
fmt.Println("Description:",ff)
var pfile P_file
pfile.total = len(objects.object)
pfile.beans = objects
packed := packElements(pfile)
marshalled, err := xml.MarshalIndent(packed,""," ")
ioutil.WriteFile("xmlout.xml",marshalled, 0644)
fmt.Println(objects.object["Address"])
for k,_ := range objects.object {
fmt.Println(k)
}
fmt.Println(len(objects.object))
a := 42
point := &a
fmt.Println(*point)
fmt.Println(&point)
fmt.Println(point)
line, _ := fmt.Println(point)
fmt.Println(line)
a = 21
fmt.Println(*point)
defer xmlfile.Close()
}