-
-
Notifications
You must be signed in to change notification settings - Fork 80
/
xmlComplexType.go
45 lines (40 loc) · 1.27 KB
/
xmlComplexType.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
// 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"
// OnComplexType handles parsing event on the complex start elements. A
// complex element contains other elements and/or attributes.
func (opt *Options) OnComplexType(ele xml.StartElement, protoTree []interface{}) (err error) {
if opt.ComplexType.Len() > 0 {
e := opt.Element.Pop().(*Element)
opt.ComplexType.Push(&ComplexType{
Name: e.Name,
})
}
if opt.ComplexType.Len() == 0 {
c := ComplexType{}
opt.CurrentEle = opt.InElement
for _, attr := range ele.Attr {
if attr.Name.Local == "name" {
c.Name = attr.Value
}
}
if c.Name == "" {
e := opt.Element.Pop().(*Element)
c.Name = e.Name
}
opt.ComplexType.Push(&c)
}
return
}
// EndComplexType handles parsing event on the complex end elements.
func (opt *Options) EndComplexType(ele xml.EndElement, protoTree []interface{}) (err error) {
opt.ProtoTree = append(opt.ProtoTree, opt.ComplexType.Pop())
opt.CurrentEle = ""
return
}