File tree Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -114,6 +114,9 @@ func Normalize(docs ...[]byte) ([]*xmltree.Element, error) {
114114 if err := nameAnonymousTypes (root , & typeCounter ); err != nil {
115115 return nil , err
116116 }
117+ if err := setChoicesOptional (root ); err != nil {
118+ return nil , err
119+ }
117120 }
118121 for _ , root := range result {
119122 expandComplexShorthand (root )
@@ -235,6 +238,31 @@ func copyEltNamesToAnonTypes(root *xmltree.Element) {
235238 }
236239}
237240
241+ // Inside a <xs:choice>, set all children to optional
242+ // If child is a <xs:sequence> set its children to optional
243+ func setChoicesOptional (root * xmltree.Element ) error {
244+
245+ for _ , el := range root .SearchFunc (isElem (schemaNS , "choice" )) {
246+ for i := 0 ; i < len (el .Children ); i ++ {
247+ t := el .Children [i ]
248+
249+ if t .Name .Space == schemaNS && t .Name .Local == "sequence" {
250+ for j := 0 ; j < len (t .Children ); j ++ {
251+ t2 := t .Children [j ]
252+ t2 .SetAttr ("" , "minOccurs" , "0" )
253+ t .Children [j ] = t2
254+ }
255+ } else {
256+ t .SetAttr ("" , "minOccurs" , "0" )
257+ }
258+
259+ el .Children [i ] = t
260+ }
261+ }
262+
263+ return nil
264+ }
265+
238266/*
239267Convert
240268
You can’t perform that action at this time.
0 commit comments