forked from GoComply/xsd2go
/
content.go
88 lines (77 loc) · 2.11 KB
/
content.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
package xsd
import (
"encoding/xml"
)
type GenericContent interface {
Attributes() []Attribute
Elements() []Element
ContainsText() bool
compile(*Schema, *Element)
}
type SimpleContent struct {
XMLName xml.Name `xml:"http://www.w3.org/2001/XMLSchema simpleContent"`
Extension *Extension `xml:"extension"`
Restriction *Restriction `xml:"restriction"`
schema *Schema `xml:"-"`
}
func (sc *SimpleContent) Attributes() []Attribute {
if sc.Extension != nil {
return sc.Extension.Attributes()
} else if sc.Restriction != nil {
return sc.Restriction.Attributes()
}
return []Attribute{}
}
func (sc *SimpleContent) ContainsText() bool {
return sc.Extension != nil && sc.Extension.ContainsText()
}
func (sc *SimpleContent) Elements() []Element {
if sc.Extension != nil {
return sc.Extension.Elements()
}
return []Element{}
}
func (sc *SimpleContent) compile(sch *Schema, parentElement *Element) {
sc.schema = sch
if sc.Extension != nil {
sc.Extension.compile(sch, parentElement)
}
if sc.Restriction != nil {
sc.Restriction.compile(sch, parentElement)
}
}
type ComplexContent struct {
XMLName xml.Name `xml:"http://www.w3.org/2001/XMLSchema complexContent"`
Extension *Extension `xml:"extension"`
Restriction *Restriction `xml:"restriction"`
schema *Schema `xml:"-"`
}
func (cc *ComplexContent) Attributes() []Attribute {
if cc.Extension != nil {
return cc.Extension.Attributes()
} else if cc.Restriction != nil {
return cc.Restriction.Attributes()
}
return []Attribute{}
}
func (cc *ComplexContent) Elements() []Element {
if cc.Extension != nil {
return cc.Extension.Elements()
}
return []Element{}
}
func (cc *ComplexContent) ContainsText() bool {
return cc.Extension != nil && cc.Extension.ContainsText()
}
func (c *ComplexContent) compile(sch *Schema, parentElement *Element) {
c.schema = sch
if c.Extension != nil {
c.Extension.compile(sch, parentElement)
}
if c.Restriction != nil {
if c.Extension != nil {
panic("Not implemented: xsd:complexContent defines xsd:restriction and xsd:extension")
}
c.Restriction.compile(sch, parentElement)
}
}