-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinterfaces.go
120 lines (102 loc) · 2.16 KB
/
interfaces.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
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
package dom
import(
"io"
)
type Kind int
const (
NodeKind = iota
ElementKind
CommentKind
DirectiveKind
ProcInstKind
DeclarationKind
TextKind
)
// represents an arbitrary xml node
// xml declaration and root element
// have Parent() == null
type Node interface{
Parent() Node
SetParent(n Node)
ChildNodes() []Node
ChildAt(index int) (Node, error)
AppendChildNode(n Node)
Store() DOMStore
String() string
Kind() Kind
}
// represents an xml element
// ChildNodes() also returns Data as Text
type Element interface{
Node
Prefix() string
Name() string
Attr() []Attribute
Text() string
}
// represents an xml attribute
// ChildNodes() always returns nil
type Attribute interface{
Prefix() string
Name() string
Value() string
String() string
}
// represents an xml comment (<!-- $text -->).
// ChildNodes() will return slice with $text
type Comment interface{
Node
Data
}
// represents an xml processing instruction (<?--$target $text-->)
// ChildNodes() will return slice with $text
type ProcInst interface{
Node
Data
Target() string
}
// represents Data as a node
// Data() returns the text contents
type Text interface{
Node
Data
}
// represents the top level xml declaration
// it is a processing instruction with Target()=="xml"
type Declaration interface{
ProcInst
}
// represents an xml directive (<!text ...>)
type Directive interface{
Node
Data
}
// returns the text contents of text nodes
type Data interface{
Data() string
}
// represents a DOM
// by returning Root() you can navigate deeper
// other dom functions like GetElementsById etc
// might be added later
type DOM interface{
Node
Declaration() Declaration
Root() Element
}
// builds an DOM
// by default the DOM is read from a file
type DOMBuilder interface{
Build() (DOM, error)
Reader()(reader io.Reader)
}
type DOMStore interface{
NewDOM() DOM
CreateElement(prefix string, name string, attr []Attribute) Element
CreateAttribute(prefix string, name string, value string) Attribute
CreateProcInst(target string, data string) ProcInst
CreateComment(data string) Comment
CreateText(data string) Text
CreateDeclaration(data string) Declaration
CreateDirective(data string) Directive
}