-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathelement.go
65 lines (54 loc) · 971 Bytes
/
element.go
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
package xmler
import "container/list"
type Attr struct {
Name string
Value string
}
type Element struct {
Id string
Type string
Value string
Parent *Element
Attrs []Attr
}
func (self *Element) addAttr(name, value string) {
if name == "id" {
self.Id = value
} else {
self.Attrs = append(
self.Attrs,
Attr{
Name: name,
Value: value,
},
)
}
}
func (self *Element) Name() string {
if self.Id != "" {
return self.Id
}
return self.Type
}
func (self *Element) IdentifierName() string {
instanceName := self.Name()
if self.Id == "" && self.Parent != nil {
return self.Parent.Name() + instanceName
}
return instanceName
}
type Elements struct {
*list.List
}
func NewElements() Elements {
return Elements{
list.New(),
}
}
func (self *Elements) Slice() []*Element {
var elements []*Element
for e := self.Front(); e != nil; e = e.Next() {
elements = append(elements, e.Value.(*Element))
}
return elements
}