-
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathdtd_attr.go
More file actions
76 lines (65 loc) · 2.2 KB
/
Copy pathdtd_attr.go
File metadata and controls
76 lines (65 loc) · 2.2 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
package helium
import "github.com/lestrrat-go/helium/enum"
// AttributeDecl is an xml attribute declaration from DTD.
type AttributeDecl struct {
docnode
atype enum.AttributeType // attribute type
def enum.AttributeDefault // default
defvalue string // ... or the default value
tree Enumeration // ... or the enumeration tree, if any
prefix string // the namespace prefix, if any
elem string // name of the element holding the attribute
external bool // declared in external markup (external subset or external PE)
}
func newAttributeDecl() *AttributeDecl {
attr := &AttributeDecl{}
attr.etype = AttributeDeclNode
return attr
}
// AddChild adds cur as a child of this attribute declaration node.
func (n *AttributeDecl) AddChild(cur Node) error {
return addChild(n, cur)
}
// AppendText appends the given bytes to this attribute declaration's
// text content.
func (n *AttributeDecl) AppendText(b []byte) error {
return appendText(n, b)
}
// AddSibling inserts cur as the next sibling of this attribute
// declaration in the DTD's declaration list.
func (n *AttributeDecl) AddSibling(cur Node) error {
return addSibling(n, cur)
}
// Replace replaces this attribute declaration node with the given nodes.
func (n *AttributeDecl) Replace(nodes ...Node) error {
return replaceNode(n, nodes...)
}
// SetTreeDoc recursively sets the owner document for this attribute
// declaration and all of its children.
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 lookupAttributeDecl(doc *Document, name, prefix, elem string) *AttributeDecl {
if doc == nil {
return nil
}
if dtd := doc.IntSubset(); dtd != nil {
if decl, ok := dtd.LookupAttribute(name, prefix, elem); ok {
return decl
}
}
if dtd := doc.ExtSubset(); dtd != nil {
if decl, ok := dtd.LookupAttribute(name, prefix, elem); ok {
return decl
}
}
return nil
}