-
-
Notifications
You must be signed in to change notification settings - Fork 80
/
xmlSimpleType.go
48 lines (43 loc) · 1.58 KB
/
xmlSimpleType.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
// 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 "encoding/xml"
// OnSimpleType handles parsing event on the simpleType start elements. The
// simpleType element defines a simple type and specifies the constraints and
// information about the values of attributes or text-only elements.
func (opt *Options) OnSimpleType(ele xml.StartElement, protoTree []interface{}) (err error) {
if opt.SimpleType.Len() == 0 {
opt.SimpleType.Push(&SimpleType{})
}
if opt.CurrentEle == "attributeGroup" {
// return
}
opt.CurrentEle = opt.InElement
for _, attr := range ele.Attr {
if attr.Name.Local == "name" {
opt.SimpleType.Peek().(*SimpleType).Name = attr.Value
}
}
return
}
// EndSimpleType handles parsing event on the simpleType end elements.
func (opt *Options) EndSimpleType(ele xml.EndElement, protoTree []interface{}) (err error) {
if opt.SimpleType.Len() > 0 && opt.Attribute.Len() > 0 {
opt.Attribute.Peek().(*Attribute).Type = opt.SimpleType.Pop().(*SimpleType).Base
return
}
if ele.Name.Local == opt.CurrentEle && opt.ComplexType.Len() == 1 {
opt.ProtoTree = append(opt.ProtoTree, opt.ComplexType.Pop())
opt.CurrentEle = ""
}
if ele.Name.Local == opt.CurrentEle && !opt.InUnion {
opt.ProtoTree = append(opt.ProtoTree, opt.SimpleType.Pop())
opt.CurrentEle = ""
}
return
}