-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathattr.go
More file actions
132 lines (106 loc) · 2.56 KB
/
attr.go
File metadata and controls
132 lines (106 loc) · 2.56 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
package helium
import "github.com/lestrrat-go/helium/enum"
type Enumeration []string
// Attribute represents an XML attribute (libxml2: xmlAttr).
type Attribute struct {
docnode
atype enum.AttributeType
defaultAttr bool
ns *Namespace
}
func newAttributeDecl() *AttributeDecl {
attr := &AttributeDecl{}
attr.etype = AttributeDeclNode
return attr
}
func (n *AttributeDecl) AddChild(cur Node) error {
return addChild(n, cur)
}
func (n *AttributeDecl) AppendText(b []byte) error {
return appendText(n, b)
}
func (n *AttributeDecl) AddSibling(cur Node) error {
return addSibling(n, cur)
}
func (n *AttributeDecl) Replace(cur Node) error {
return replaceNode(n, cur)
}
func (n *AttributeDecl) SetTreeDoc(doc *Document) {
setTreeDoc(n, doc)
}
// AType returns the attribute type (e.g. enum.AttrID, enum.AttrCDATA).
func (n *AttributeDecl) AType() enum.AttributeType {
return n.atype
}
// Elem returns the element name this attribute declaration belongs to.
func (n *AttributeDecl) Elem() string {
return n.elem
}
func newAttribute(name string, ns *Namespace) *Attribute {
attr := &Attribute{}
attr.etype = AttributeNode
attr.name = name
attr.ns = ns
return attr
}
// NextAttribute is a thin wrapper around NextSibling() so that the
// caller does not have to constantly type assert
func (n *Attribute) NextAttribute() *Attribute {
next := n.NextSibling()
if next == nil {
return nil
}
return next.(*Attribute)
}
func (n *Attribute) AddChild(cur Node) error {
return addChild(n, cur)
}
func (n *Attribute) AppendText(b []byte) error {
return appendText(n, b)
}
func (n *Attribute) AddSibling(cur Node) error {
return addSibling(n, cur)
}
func (n *Attribute) Replace(cur Node) error {
return replaceNode(n, cur)
}
func (n *Attribute) SetTreeDoc(doc *Document) {
setTreeDoc(n, doc)
}
// AType returns the attribute type (e.g. enum.AttrID, enum.AttrCDATA).
func (n *Attribute) AType() enum.AttributeType {
return n.atype
}
// SetAType sets the attribute type.
func (n *Attribute) SetAType(v enum.AttributeType) {
n.atype = v
}
func (n *Attribute) SetDefault(b bool) {
n.defaultAttr = b
}
func (n *Attribute) IsDefault() bool {
return n.defaultAttr
}
func (n Attribute) Value() string {
return string(n.Content())
}
func (n Attribute) Name() string {
if n.ns != nil {
if p := n.ns.Prefix(); p != "" {
return p + ":" + n.docnode.Name()
}
}
return n.docnode.Name()
}
func (n Attribute) Prefix() string {
if n.ns == nil {
return ""
}
return n.ns.Prefix()
}
func (n Attribute) URI() string {
if n.ns == nil {
return ""
}
return n.ns.URI()
}