-
-
Notifications
You must be signed in to change notification settings - Fork 80
/
proto.go
136 lines (126 loc) · 4.93 KB
/
proto.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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
// Copyright 2020 - 2024 The xgen Authors. All rights reserved. Use of this
// source code is governed by a BSD-style license that can be found in the
// LICENSE file.
//
// Package xgen written in pure Go providing a set of functions that allow you
// to parse XSD (XML schema files). This library needs Go version 1.10 or
// later.
package xgen
import "regexp"
// SimpleType definitions provide for constraining character information item
// [children] of element and attribute information items.
// https://www.w3.org/TR/xmlschema-1/#Simple_Type_Definitions
type SimpleType struct {
Doc string
Name string
Base string
Anonymous bool
List bool
Union bool
MemberTypes map[string]string
Restriction Restriction
}
// Element declarations provide for: Local validation of element information
// item values using a type definition; Specifying default or fixed values for
// an element information items; Establishing uniquenesses and reference
// constraint relationships among the values of related elements and
// attributes; Controlling the substitutability of elements through the
// mechanism of element substitution groups.
// https://www.w3.org/TR/xmlschema-1/#cElement_Declarations
type Element struct {
Doc string
Name string
Wildcard bool
Type string
Abstract bool
Plural bool
Optional bool
Nillable bool
Default string
}
// Attribute declarations provide for: Local validation of attribute
// information item values using a simple type definition; Specifying default
// or fixed values for attribute information items.
// https://www.w3.org/TR/xmlschema-1/structures.html#element-attribute
type Attribute struct {
Name string
Doc string
Type string
Plural bool
Default string
Optional bool
}
// ComplexType definitions are identified by their {name} and {target
// namespace}. Except for anonymous complex type definitions (those with no
// {name}), since type definitions (i.e. both simple and complex type
// definitions taken together) must be uniquely identified within an ·XML
// Schema·, no complex type definition can have the same name as another
// simple or complex type definition. Complex type {name}s and {target
// namespace}s are provided for reference from instances, and for use in the
// XML representation of schema components (specifically in <element>). See
// References to schema components across namespaces for the use of component
// identifiers when importing one schema into another.
// https://www.w3.org/TR/xmlschema-1/structures.html#element-complexType
type ComplexType struct {
Doc string
Name string
Base string
Anonymous bool
Elements []Element
Attributes []Attribute
Groups []Group
Choice []Choice
AttributeGroup []AttributeGroup
Mixed bool
}
// Group (model group) definitions are provided primarily for reference from
// the XML Representation of Complex Type Definitions. Thus, model group
// definitions provide a replacement for some uses of XML's parameter entity
// facility.
// https://www.w3.org/TR/xmlschema-1/structures.html#cModel_Group_Definitions
type Group struct {
Doc string
Name string
Elements []Element
Groups []Group
Plural bool
Ref string
}
// Choice definitions are provided primarily for reference from
// the XML Representation of Choice Definitions which acts as a container
// stating that one and only one element in the selected group should be
// present in the containing element. Generated code does not enforce the "one
// and only one" constraint but the choice container is parsed in order to effectively
// define if the elements it contains should be plural or not (as defined by the maxOccurs).
// https://www.w3.org/TR/xmlschema-1/#Complex_Type_Definition_details
type Choice struct {
ID string
Choice []Choice
Plural bool
}
// AttributeGroup definitions do not participate in ·validation· as such, but
// the {attribute uses} and {attribute wildcard} of one or more complex type
// definitions may be constructed in whole or part by reference to an
// attribute group. Thus, attribute group definitions provide a replacement
// for some uses of XML's parameter entity facility. Attribute group
// definitions are provided primarily for reference from the XML
// representation of schema components (see <complexType> and
// <attributeGroup>).
// https://www.w3.org/TR/xmlschema-1/structures.html#Attribute_Group_Definition
type AttributeGroup struct {
Doc string
Name string
Ref string
Attributes []Attribute
}
// Restriction are used to define acceptable values for XML elements or
// attributes. Restriction on XML elements are called facets.
// https://www.w3.org/TR/xmlschema-1/structures.html#element-restriction
type Restriction struct {
Doc string
Precision int
Enum []string
Min, Max float64
MinLength, MaxLength int
Pattern *regexp.Regexp
}