Skip to content

Commit 04f2cd7

Browse files
committed
This close #23, use single element instead of the array when max occur is less than 2
1 parent 05299ff commit 04f2cd7

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

xmlElement.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@
88

99
package xgen
1010

11-
import "encoding/xml"
11+
import (
12+
"encoding/xml"
13+
"strconv"
14+
)
1215

1316
// OnElement handles parsing event on the element start elements.
1417
func (opt *Options) OnElement(ele xml.StartElement, protoTree []interface{}) (err error) {
@@ -32,8 +35,12 @@ func (opt *Options) OnElement(ele xml.StartElement, protoTree []interface{}) (er
3235
}
3336
}
3437
if attr.Name.Local == "maxOccurs" {
35-
if attr.Value != "0" {
36-
e.Plural = true
38+
var maxOccurs int
39+
if maxOccurs, err = strconv.Atoi(attr.Value); attr.Value != "unbounded" && err != nil {
40+
return
41+
}
42+
if attr.Value == "unbounded" || maxOccurs > 1 {
43+
e.Plural, err = true, nil
3744
}
3845
}
3946
if attr.Name.Local == "unbounded" {

0 commit comments

Comments
 (0)