diff --git a/cmd/xgen/xgen.go b/cmd/xgen/xgen.go index 921ef80..c5644fa 100644 --- a/cmd/xgen/xgen.go +++ b/cmd/xgen/xgen.go @@ -117,6 +117,7 @@ func main() { NSSchemaLocationMap: make(map[string]string), ParseFileList: make(map[string]bool), ParseFileMap: make(map[string][]interface{}), + ProtoTree: make([]interface{}, 0), }) if _, err = parser.Parse(); err != nil { fmt.Println(err) diff --git a/coverage.txt b/coverage.txt deleted file mode 100644 index 8dabd46..0000000 --- a/coverage.txt +++ /dev/null @@ -1,317 +0,0 @@ -mode: atomic -github.com/xuri/xgen/parser.go:49.43,51.2 1 3 -github.com/xuri/xgen/parser.go:56.66,60.16 4 3 -github.com/xuri/xgen/parser.go:63.2,63.16 1 3 -github.com/xuri/xgen/parser.go:66.2,68.16 3 1 -github.com/xuri/xgen/parser.go:71.2,71.18 1 1 -github.com/xuri/xgen/parser.go:75.2,92.6 15 1 -github.com/xuri/xgen/parser.go:180.2,182.18 2 1 -github.com/xuri/xgen/parser.go:189.2,189.8 1 1 -github.com/xuri/xgen/parser.go:60.16,62.3 1 0 -github.com/xuri/xgen/parser.go:63.16,65.3 1 2 -github.com/xuri/xgen/parser.go:68.16,70.3 1 0 -github.com/xuri/xgen/parser.go:71.18,74.3 2 1 -github.com/xuri/xgen/parser.go:92.6,94.19 2 70 -github.com/xuri/xgen/parser.go:98.3,98.34 1 69 -github.com/xuri/xgen/parser.go:94.19,95.9 1 1 -github.com/xuri/xgen/parser.go:99.25,104.27 4 19 -github.com/xuri/xgen/parser.go:112.23,113.33 1 19 -github.com/xuri/xgen/parser.go:125.4,125.32 1 16 -github.com/xuri/xgen/parser.go:148.4,148.58 1 16 -github.com/xuri/xgen/parser.go:151.4,151.39 1 16 -github.com/xuri/xgen/parser.go:157.4,157.24 1 16 -github.com/xuri/xgen/parser.go:169.4,169.33 1 16 -github.com/xuri/xgen/parser.go:177.11,177.11 0 31 -github.com/xuri/xgen/parser.go:104.27,106.23 2 13 -github.com/xuri/xgen/parser.go:106.23,109.6 2 0 -github.com/xuri/xgen/parser.go:113.33,114.75 1 13 -github.com/xuri/xgen/parser.go:119.5,119.44 1 10 -github.com/xuri/xgen/parser.go:114.75,117.14 3 3 -github.com/xuri/xgen/parser.go:119.44,122.14 3 0 -github.com/xuri/xgen/parser.go:125.32,126.61 1 5 -github.com/xuri/xgen/parser.go:130.5,130.38 1 5 -github.com/xuri/xgen/parser.go:133.5,133.30 1 5 -github.com/xuri/xgen/parser.go:140.5,140.61 1 5 -github.com/xuri/xgen/parser.go:126.61,129.6 2 2 -github.com/xuri/xgen/parser.go:130.38,132.6 1 0 -github.com/xuri/xgen/parser.go:133.30,135.20 2 0 -github.com/xuri/xgen/parser.go:138.6,138.25 1 0 -github.com/xuri/xgen/parser.go:135.20,137.7 1 0 -github.com/xuri/xgen/parser.go:140.61,142.20 2 0 -github.com/xuri/xgen/parser.go:145.6,145.25 1 0 -github.com/xuri/xgen/parser.go:142.20,144.7 1 0 -github.com/xuri/xgen/parser.go:148.58,150.5 1 0 -github.com/xuri/xgen/parser.go:151.39,152.60 1 3 -github.com/xuri/xgen/parser.go:152.60,154.6 1 0 -github.com/xuri/xgen/parser.go:157.24,158.65 1 0 -github.com/xuri/xgen/parser.go:164.5,164.45 1 0 -github.com/xuri/xgen/parser.go:158.65,163.6 4 0 -github.com/xuri/xgen/parser.go:164.45,166.6 1 0 -github.com/xuri/xgen/parser.go:169.33,170.69 1 0 -github.com/xuri/xgen/parser.go:170.69,175.6 4 0 -github.com/xuri/xgen/parser.go:182.18,185.102 3 1 -github.com/xuri/xgen/parser.go:185.102,187.4 1 0 -github.com/xuri/xgen/parser.go:194.103,195.60 1 9 -github.com/xuri/xgen/parser.go:199.2,200.57 2 2 -github.com/xuri/xgen/parser.go:203.2,203.17 1 2 -github.com/xuri/xgen/parser.go:206.2,210.16 5 2 -github.com/xuri/xgen/parser.go:213.2,213.16 1 2 -github.com/xuri/xgen/parser.go:217.2,218.9 2 0 -github.com/xuri/xgen/parser.go:232.2,233.57 2 0 -github.com/xuri/xgen/parser.go:236.2,245.16 2 0 -github.com/xuri/xgen/parser.go:248.2,249.8 2 0 -github.com/xuri/xgen/parser.go:195.60,198.3 2 7 -github.com/xuri/xgen/parser.go:200.57,202.3 1 0 -github.com/xuri/xgen/parser.go:203.17,205.3 1 0 -github.com/xuri/xgen/parser.go:210.16,212.3 1 0 -github.com/xuri/xgen/parser.go:213.16,215.3 1 2 -github.com/xuri/xgen/parser.go:218.9,228.17 2 0 -github.com/xuri/xgen/parser.go:228.17,230.4 1 0 -github.com/xuri/xgen/parser.go:233.57,235.3 1 0 -github.com/xuri/xgen/parser.go:245.16,247.3 1 0 -github.com/xuri/xgen/schema.go:15.69,16.35 1 1 -github.com/xuri/xgen/schema.go:21.2,21.8 1 1 -github.com/xuri/xgen/schema.go:16.35,17.32 1 2 -github.com/xuri/xgen/schema.go:17.32,19.4 1 0 -github.com/xuri/xgen/schema.go:24.74,26.35 2 0 -github.com/xuri/xgen/schema.go:34.2,34.8 1 0 -github.com/xuri/xgen/schema.go:26.35,27.36 1 0 -github.com/xuri/xgen/schema.go:30.3,30.41 1 0 -github.com/xuri/xgen/schema.go:27.36,29.4 1 0 -github.com/xuri/xgen/schema.go:30.41,32.4 1 0 -github.com/xuri/xgen/schema.go:37.53,39.2 1 2 -github.com/xuri/xgen/stack.go:24.24,26.2 1 3 -github.com/xuri/xgen/stack.go:29.27,31.2 1 59 -github.com/xuri/xgen/stack.go:34.36,35.19 1 16 -github.com/xuri/xgen/stack.go:38.2,38.20 1 16 -github.com/xuri/xgen/stack.go:35.19,37.3 1 0 -github.com/xuri/xgen/stack.go:42.35,43.19 1 5 -github.com/xuri/xgen/stack.go:47.2,50.16 4 5 -github.com/xuri/xgen/stack.go:43.19,45.3 1 0 -github.com/xuri/xgen/stack.go:54.41,58.2 3 5 -github.com/xuri/xgen/xmlAttribute.go:13.92,17.32 2 2 -github.com/xuri/xgen/xmlAttribute.go:40.2,40.31 1 2 -github.com/xuri/xgen/xmlAttribute.go:45.2,45.26 1 0 -github.com/xuri/xgen/xmlAttribute.go:52.2,53.8 2 0 -github.com/xuri/xgen/xmlAttribute.go:17.32,18.31 1 4 -github.com/xuri/xgen/xmlAttribute.go:25.3,25.32 1 4 -github.com/xuri/xgen/xmlAttribute.go:28.3,28.32 1 4 -github.com/xuri/xgen/xmlAttribute.go:34.3,34.31 1 4 -github.com/xuri/xgen/xmlAttribute.go:18.31,21.18 3 0 -github.com/xuri/xgen/xmlAttribute.go:21.18,23.5 1 0 -github.com/xuri/xgen/xmlAttribute.go:25.32,27.4 1 2 -github.com/xuri/xgen/xmlAttribute.go:28.32,30.18 2 2 -github.com/xuri/xgen/xmlAttribute.go:30.18,32.5 1 0 -github.com/xuri/xgen/xmlAttribute.go:34.31,35.32 1 0 -github.com/xuri/xgen/xmlAttribute.go:35.32,37.5 1 0 -github.com/xuri/xgen/xmlAttribute.go:40.31,43.3 2 2 -github.com/xuri/xgen/xmlAttribute.go:45.26,46.32 1 0 -github.com/xuri/xgen/xmlAttribute.go:49.3,49.9 1 0 -github.com/xuri/xgen/xmlAttribute.go:46.32,48.4 1 0 -github.com/xuri/xgen/xmlComplexType.go:13.94,14.31 1 3 -github.com/xuri/xgen/xmlComplexType.go:21.2,21.32 1 3 -github.com/xuri/xgen/xmlComplexType.go:35.2,35.8 1 3 -github.com/xuri/xgen/xmlComplexType.go:14.31,19.3 2 0 -github.com/xuri/xgen/xmlComplexType.go:21.32,24.33 3 3 -github.com/xuri/xgen/xmlComplexType.go:29.3,29.19 1 3 -github.com/xuri/xgen/xmlComplexType.go:33.3,33.27 1 3 -github.com/xuri/xgen/xmlComplexType.go:24.33,25.33 1 3 -github.com/xuri/xgen/xmlComplexType.go:25.33,27.5 1 3 -github.com/xuri/xgen/xmlComplexType.go:29.19,32.4 2 0 -github.com/xuri/xgen/xmlRestriction.go:13.94,14.32 1 2 -github.com/xuri/xgen/xmlRestriction.go:29.2,29.8 1 2 -github.com/xuri/xgen/xmlRestriction.go:14.32,15.32 1 2 -github.com/xuri/xgen/xmlRestriction.go:15.32,18.18 3 2 -github.com/xuri/xgen/xmlRestriction.go:21.4,21.36 1 2 -github.com/xuri/xgen/xmlRestriction.go:18.18,20.5 1 0 -github.com/xuri/xgen/xmlRestriction.go:21.36,23.19 2 2 -github.com/xuri/xgen/xmlRestriction.go:23.19,25.6 1 0 -github.com/xuri/xgen/utils.go:19.59,22.16 3 1 -github.com/xuri/xgen/utils.go:25.2,25.16 1 1 -github.com/xuri/xgen/utils.go:34.2,35.8 2 1 -github.com/xuri/xgen/utils.go:22.16,24.3 1 0 -github.com/xuri/xgen/utils.go:25.16,26.80 1 1 -github.com/xuri/xgen/utils.go:30.3,30.17 1 1 -github.com/xuri/xgen/utils.go:26.80,29.4 2 2 -github.com/xuri/xgen/utils.go:30.17,32.4 1 0 -github.com/xuri/xgen/utils.go:40.42,41.16 1 1 -github.com/xuri/xgen/utils.go:44.2,45.24 2 1 -github.com/xuri/xgen/utils.go:50.2,50.12 1 1 -github.com/xuri/xgen/utils.go:41.16,43.3 1 0 -github.com/xuri/xgen/utils.go:45.24,46.49 1 0 -github.com/xuri/xgen/utils.go:46.49,48.4 1 0 -github.com/xuri/xgen/utils.go:106.73,107.32 1 9 -github.com/xuri/xgen/utils.go:123.2,123.13 1 9 -github.com/xuri/xgen/utils.go:107.32,108.26 1 39 -github.com/xuri/xgen/utils.go:109.20,110.45 1 15 -github.com/xuri/xgen/utils.go:113.19,114.22 1 0 -github.com/xuri/xgen/utils.go:117.17,118.22 1 0 -github.com/xuri/xgen/utils.go:110.45,112.5 1 0 -github.com/xuri/xgen/utils.go:114.22,116.5 1 0 -github.com/xuri/xgen/utils.go:118.22,120.5 1 0 -github.com/xuri/xgen/utils.go:126.42,128.21 2 2 -github.com/xuri/xgen/utils.go:132.2,132.8 1 2 -github.com/xuri/xgen/utils.go:128.21,131.3 2 0 -github.com/xuri/xgen/utils.go:135.45,137.21 2 20 -github.com/xuri/xgen/utils.go:141.2,142.8 2 20 -github.com/xuri/xgen/utils.go:137.21,140.3 2 0 -github.com/xuri/xgen/utils.go:146.42,148.16 1 39 -github.com/xuri/xgen/utils.go:152.2,157.52 4 39 -github.com/xuri/xgen/utils.go:148.16,150.3 1 0 -github.com/xuri/xgen/xmlElement.go:13.90,15.32 2 3 -github.com/xuri/xgen/xmlElement.go:40.2,40.18 1 3 -github.com/xuri/xgen/xmlElement.go:47.2,47.31 1 3 -github.com/xuri/xgen/xmlElement.go:52.2,52.21 1 0 -github.com/xuri/xgen/xmlElement.go:59.2,60.8 2 0 -github.com/xuri/xgen/xmlElement.go:15.32,16.31 1 6 -github.com/xuri/xgen/xmlElement.go:24.3,24.32 1 6 -github.com/xuri/xgen/xmlElement.go:27.3,27.32 1 6 -github.com/xuri/xgen/xmlElement.go:33.3,33.37 1 6 -github.com/xuri/xgen/xmlElement.go:16.31,19.18 3 0 -github.com/xuri/xgen/xmlElement.go:19.18,21.5 1 0 -github.com/xuri/xgen/xmlElement.go:24.32,26.4 1 3 -github.com/xuri/xgen/xmlElement.go:27.32,29.18 2 3 -github.com/xuri/xgen/xmlElement.go:29.18,31.5 1 0 -github.com/xuri/xgen/xmlElement.go:33.37,34.25 1 0 -github.com/xuri/xgen/xmlElement.go:34.25,36.5 1 0 -github.com/xuri/xgen/xmlElement.go:40.18,42.17 2 0 -github.com/xuri/xgen/xmlElement.go:45.3,45.23 1 0 -github.com/xuri/xgen/xmlElement.go:42.17,44.4 1 0 -github.com/xuri/xgen/xmlElement.go:47.31,50.3 2 3 -github.com/xuri/xgen/xmlElement.go:52.21,53.23 1 0 -github.com/xuri/xgen/xmlElement.go:56.3,56.9 1 0 -github.com/xuri/xgen/xmlElement.go:53.23,55.4 1 0 -github.com/xuri/xgen/xmlImport.go:13.89,16.2 2 0 -github.com/xuri/xgen/xmlSchema.go:13.89,16.2 2 1 -github.com/xuri/xgen/xmlUnion.go:16.88,18.34 2 0 -github.com/xuri/xgen/xmlUnion.go:21.2,23.32 3 0 -github.com/xuri/xgen/xmlUnion.go:35.2,35.8 1 0 -github.com/xuri/xgen/xmlUnion.go:18.34,20.3 1 0 -github.com/xuri/xgen/xmlUnion.go:23.32,24.39 1 0 -github.com/xuri/xgen/xmlUnion.go:24.39,26.43 2 0 -github.com/xuri/xgen/xmlUnion.go:32.4,32.12 1 0 -github.com/xuri/xgen/xmlUnion.go:26.43,28.19 2 0 -github.com/xuri/xgen/xmlUnion.go:28.19,30.6 1 0 -github.com/xuri/xgen/xmlGroup.go:13.88,15.32 2 0 -github.com/xuri/xgen/xmlGroup.go:32.2,32.32 1 0 -github.com/xuri/xgen/xmlGroup.go:46.2,46.31 1 0 -github.com/xuri/xgen/xmlGroup.go:50.2,50.8 1 0 -github.com/xuri/xgen/xmlGroup.go:15.32,16.32 1 0 -github.com/xuri/xgen/xmlGroup.go:19.3,19.31 1 0 -github.com/xuri/xgen/xmlGroup.go:26.3,26.37 1 0 -github.com/xuri/xgen/xmlGroup.go:16.32,18.4 1 0 -github.com/xuri/xgen/xmlGroup.go:19.31,22.18 3 0 -github.com/xuri/xgen/xmlGroup.go:22.18,24.5 1 0 -github.com/xuri/xgen/xmlGroup.go:26.37,27.25 1 0 -github.com/xuri/xgen/xmlGroup.go:27.25,29.5 1 0 -github.com/xuri/xgen/xmlGroup.go:32.32,33.23 1 0 -github.com/xuri/xgen/xmlGroup.go:39.3,39.22 1 0 -github.com/xuri/xgen/xmlGroup.go:33.23,38.4 4 0 -github.com/xuri/xgen/xmlGroup.go:39.22,43.4 3 0 -github.com/xuri/xgen/xmlGroup.go:46.31,49.3 2 0 -github.com/xuri/xgen/xmlSimpleType.go:13.93,14.31 1 2 -github.com/xuri/xgen/xmlSimpleType.go:17.2,18.32 2 2 -github.com/xuri/xgen/xmlSimpleType.go:23.2,23.8 1 2 -github.com/xuri/xgen/xmlSimpleType.go:14.31,16.3 1 2 -github.com/xuri/xgen/xmlSimpleType.go:18.32,19.32 1 2 -github.com/xuri/xgen/xmlSimpleType.go:19.32,21.4 1 2 -github.com/xuri/xgen/genGo.go:34.58,38.32 4 1 -github.com/xuri/xgen/genGo.go:182.2,183.16 2 1 -github.com/xuri/xgen/genGo.go:186.2,188.16 3 1 -github.com/xuri/xgen/genGo.go:191.2,192.16 2 1 -github.com/xuri/xgen/genGo.go:196.2,197.12 2 1 -github.com/xuri/xgen/genGo.go:38.32,39.26 1 5 -github.com/xuri/xgen/genGo.go:40.20,41.14 1 2 -github.com/xuri/xgen/genGo.go:53.4,53.41 1 2 -github.com/xuri/xgen/genGo.go:69.4,69.39 1 2 -github.com/xuri/xgen/genGo.go:75.21,76.39 1 3 -github.com/xuri/xgen/genGo.go:121.15,122.39 1 0 -github.com/xuri/xgen/genGo.go:144.24,145.39 1 0 -github.com/xuri/xgen/genGo.go:159.17,160.39 1 0 -github.com/xuri/xgen/genGo.go:170.19,171.39 1 0 -github.com/xuri/xgen/genGo.go:41.14,42.40 1 0 -github.com/xuri/xgen/genGo.go:42.40,44.34 2 0 -github.com/xuri/xgen/genGo.go:47.6,50.14 4 0 -github.com/xuri/xgen/genGo.go:44.34,46.7 1 0 -github.com/xuri/xgen/genGo.go:53.41,54.40 1 0 -github.com/xuri/xgen/genGo.go:67.5,67.13 1 0 -github.com/xuri/xgen/genGo.go:54.40,56.56 2 0 -github.com/xuri/xgen/genGo.go:62.6,64.82 3 0 -github.com/xuri/xgen/genGo.go:56.56,57.27 1 0 -github.com/xuri/xgen/genGo.go:60.7,60.95 1 0 -github.com/xuri/xgen/genGo.go:57.27,59.8 1 0 -github.com/xuri/xgen/genGo.go:69.39,73.5 3 2 -github.com/xuri/xgen/genGo.go:76.39,78.48 2 3 -github.com/xuri/xgen/genGo.go:86.5,86.44 1 3 -github.com/xuri/xgen/genGo.go:97.5,97.36 1 3 -github.com/xuri/xgen/genGo.go:105.5,105.40 1 3 -github.com/xuri/xgen/genGo.go:116.5,118.81 3 3 -github.com/xuri/xgen/genGo.go:78.48,80.34 2 0 -github.com/xuri/xgen/genGo.go:83.6,83.97 1 0 -github.com/xuri/xgen/genGo.go:80.34,82.7 1 0 -github.com/xuri/xgen/genGo.go:86.44,88.28 2 2 -github.com/xuri/xgen/genGo.go:91.6,92.34 2 2 -github.com/xuri/xgen/genGo.go:95.6,95.134 1 2 -github.com/xuri/xgen/genGo.go:88.28,90.7 1 2 -github.com/xuri/xgen/genGo.go:92.34,94.7 1 0 -github.com/xuri/xgen/genGo.go:97.36,99.22 2 0 -github.com/xuri/xgen/genGo.go:102.6,102.151 1 0 -github.com/xuri/xgen/genGo.go:99.22,101.7 1 0 -github.com/xuri/xgen/genGo.go:105.40,107.24 2 3 -github.com/xuri/xgen/genGo.go:110.6,111.34 2 3 -github.com/xuri/xgen/genGo.go:114.6,114.119 1 3 -github.com/xuri/xgen/genGo.go:107.24,109.7 1 0 -github.com/xuri/xgen/genGo.go:111.34,113.7 1 1 -github.com/xuri/xgen/genGo.go:122.39,124.40 2 0 -github.com/xuri/xgen/genGo.go:132.5,132.36 1 0 -github.com/xuri/xgen/genGo.go:140.5,142.81 3 0 -github.com/xuri/xgen/genGo.go:124.40,126.24 2 0 -github.com/xuri/xgen/genGo.go:129.6,129.156 1 0 -github.com/xuri/xgen/genGo.go:126.24,128.7 1 0 -github.com/xuri/xgen/genGo.go:132.36,134.22 2 0 -github.com/xuri/xgen/genGo.go:137.6,137.151 1 0 -github.com/xuri/xgen/genGo.go:134.22,136.7 1 0 -github.com/xuri/xgen/genGo.go:145.39,147.44 2 0 -github.com/xuri/xgen/genGo.go:154.5,156.81 3 0 -github.com/xuri/xgen/genGo.go:147.44,149.28 2 0 -github.com/xuri/xgen/genGo.go:152.6,152.201 1 0 -github.com/xuri/xgen/genGo.go:149.28,151.7 1 0 -github.com/xuri/xgen/genGo.go:160.39,162.17 2 0 -github.com/xuri/xgen/genGo.go:165.5,167.81 3 0 -github.com/xuri/xgen/genGo.go:162.17,164.6 1 0 -github.com/xuri/xgen/genGo.go:171.39,173.17 2 0 -github.com/xuri/xgen/genGo.go:176.5,178.81 3 0 -github.com/xuri/xgen/genGo.go:173.17,175.6 1 0 -github.com/xuri/xgen/genGo.go:183.16,185.3 1 0 -github.com/xuri/xgen/genGo.go:188.16,190.3 1 1 -github.com/xuri/xgen/genGo.go:192.16,195.3 2 0 -github.com/xuri/xgen/genGo.go:200.51,201.47 1 10 -github.com/xuri/xgen/genGo.go:204.2,205.52 2 10 -github.com/xuri/xgen/genGo.go:208.2,210.8 3 10 -github.com/xuri/xgen/genGo.go:201.47,203.3 1 10 -github.com/xuri/xgen/genGo.go:205.52,207.3 1 10 -github.com/xuri/xgen/genGo.go:213.39,214.38 1 7 -github.com/xuri/xgen/genGo.go:217.2,218.47 2 0 -github.com/xuri/xgen/genGo.go:221.2,222.21 2 0 -github.com/xuri/xgen/genGo.go:225.2,225.22 1 0 -github.com/xuri/xgen/genGo.go:214.38,216.3 1 7 -github.com/xuri/xgen/genGo.go:218.47,220.3 1 0 -github.com/xuri/xgen/genGo.go:222.21,224.3 1 0 -github.com/xuri/xgen/xmlAttributeGroup.go:13.97,15.32 2 0 -github.com/xuri/xgen/xmlAttributeGroup.go:27.2,27.32 1 0 -github.com/xuri/xgen/xmlAttributeGroup.go:34.2,34.31 1 0 -github.com/xuri/xgen/xmlAttributeGroup.go:38.2,38.8 1 0 -github.com/xuri/xgen/xmlAttributeGroup.go:15.32,16.32 1 0 -github.com/xuri/xgen/xmlAttributeGroup.go:19.3,19.31 1 0 -github.com/xuri/xgen/xmlAttributeGroup.go:16.32,18.4 1 0 -github.com/xuri/xgen/xmlAttributeGroup.go:19.31,22.18 3 0 -github.com/xuri/xgen/xmlAttributeGroup.go:22.18,24.5 1 0 -github.com/xuri/xgen/xmlAttributeGroup.go:27.32,32.3 4 0 -github.com/xuri/xgen/xmlAttributeGroup.go:34.31,37.3 2 0 -github.com/xuri/xgen/xmlList.go:13.87,14.34 1 0 -github.com/xuri/xgen/xmlList.go:17.2,18.32 2 0 -github.com/xuri/xgen/xmlList.go:26.2,26.8 1 0 -github.com/xuri/xgen/xmlList.go:14.34,16.3 1 0 -github.com/xuri/xgen/xmlList.go:18.32,19.36 1 0 -github.com/xuri/xgen/xmlList.go:19.36,21.18 2 0 -github.com/xuri/xgen/xmlList.go:21.18,23.5 1 0 diff --git a/logo.png b/logo.png new file mode 100644 index 0000000..cef22f0 Binary files /dev/null and b/logo.png differ diff --git a/parser.go b/parser.go index e85f5d5..eac7045 100644 --- a/parser.go +++ b/parser.go @@ -29,6 +29,7 @@ type Options struct { NSSchemaLocationMap map[string]string ParseFileList map[string]bool ParseFileMap map[string][]interface{} + ProtoTree []interface{} InElement string CurrentEle string @@ -53,7 +54,7 @@ func NewParser(options *Options) *Options { // Parse reads XML documents and return proto tree for every element in the // documents by given options. If value of the properity extract is false, // parse will fetch schema used in or statements. -func (opt *Options) Parse() (protoTree []interface{}, err error) { +func (opt *Options) Parse() (err error) { opt.FileDir = filepath.Dir(opt.FilePath) var fi os.FileInfo fi, err = os.Stat(opt.FilePath) @@ -70,9 +71,9 @@ func (opt *Options) Parse() (protoTree []interface{}, err error) { } if !opt.Extract { opt.ParseFileList[opt.FilePath] = true - opt.ParseFileMap[opt.FilePath] = protoTree + opt.ParseFileMap[opt.FilePath] = opt.ProtoTree } - protoTree = make([]interface{}, 0) + opt.ProtoTree = make([]interface{}, 0) opt.InElement = "" opt.CurrentEle = "" @@ -102,7 +103,7 @@ func (opt *Options) Parse() (protoTree []interface{}, err error) { funcName := fmt.Sprintf("On%s", MakeFirstUpperCase(opt.InElement)) onEleFunc := reflect.ValueOf(opt).MethodByName(funcName) if onEleFunc.IsValid() { - rt := onEleFunc.Call([]reflect.Value{reflect.ValueOf(element), reflect.ValueOf(protoTree)}) + rt := onEleFunc.Call([]reflect.Value{reflect.ValueOf(element), reflect.ValueOf(opt.ProtoTree)}) if !rt[0].IsNil() { err = rt[0].Interface().(error) return @@ -110,79 +111,25 @@ func (opt *Options) Parse() (protoTree []interface{}, err error) { } case xml.EndElement: - if opt.ComplexType.Len() > 0 { - if element.Name.Local == opt.CurrentEle && opt.ComplexType.Len() == 1 { - protoTree = append(protoTree, opt.ComplexType.Pop()) - opt.CurrentEle = "" - continue - } - if element.Name.Local == "complexType" { - protoTree = append(protoTree, opt.ComplexType.Pop()) - opt.CurrentEle = "" - continue - } - } - if opt.SimpleType.Len() > 0 { - if element.Name.Local == opt.CurrentEle && !opt.InUnion { - protoTree = append(protoTree, opt.SimpleType.Pop()) - opt.CurrentEle = "" - } - if element.Name.Local == "union" { - opt.InUnion = false - } - if opt.Element.Len() > 0 { - opt.Element.Peek().(*Element).Type, err = opt.GetValueType(opt.SimpleType.Pop().(*SimpleType).Base, protoTree) - if err != nil { - return - } - opt.CurrentEle = "" - } - if opt.Attribute != nil && opt.SimpleType.Peek() != nil { - opt.Attribute.Type, err = opt.GetValueType(opt.SimpleType.Pop().(*SimpleType).Base, protoTree) - if err != nil { - return - } - opt.CurrentEle = "" - } - } - if opt.Attribute != nil && opt.ComplexType.Len() == 0 { - protoTree = append(protoTree, opt.Attribute) - } - if element.Name.Local == "element" { - if opt.Element.Len() > 0 && opt.ComplexType.Len() == 0 { - protoTree = append(protoTree, opt.Element.Pop()) - } - } - - if opt.Group != nil { - if element.Name.Local == opt.CurrentEle && opt.InGroup == 1 { - protoTree = append(protoTree, opt.Group) - opt.CurrentEle = "" - opt.InGroup-- - opt.Group = nil - } - if element.Name.Local == opt.CurrentEle { - opt.InGroup-- - } - - } - if opt.AttributeGroup != nil { - if element.Name.Local == opt.CurrentEle && opt.InAttributeGroup { - protoTree = append(protoTree, opt.AttributeGroup) - opt.CurrentEle = "" - opt.InAttributeGroup = false - opt.AttributeGroup = nil + funcName := fmt.Sprintf("End%s", MakeFirstUpperCase(element.Name.Local)) + onEleFunc := reflect.ValueOf(opt).MethodByName(funcName) + if onEleFunc.IsValid() { + rt := onEleFunc.Call([]reflect.Value{reflect.ValueOf(element), reflect.ValueOf(opt.ProtoTree)}) + if !rt[0].IsNil() { + err = rt[0].Interface().(error) + return } } default: } + } defer xmlFile.Close() if !opt.Extract { opt.ParseFileList[opt.FilePath] = true - opt.ParseFileMap[opt.FilePath] = protoTree - if err = genCode(filepath.Join(opt.OutputDir, filepath.Base(opt.FilePath)), protoTree); err != nil { + opt.ParseFileMap[opt.FilePath] = opt.ProtoTree + if err = genCode(filepath.Join(opt.OutputDir, filepath.Base(opt.FilePath)), opt.ProtoTree); err != nil { return } } @@ -216,7 +163,7 @@ func (opt *Options) GetValueType(value string, XSDSchema []interface{}) (valueTy depXSDSchema, ok := opt.ParseFileMap[xsdFile] if !ok { - depXSDSchema, err = NewParser(&Options{ + parser := NewParser(&Options{ FilePath: xsdFile, OutputDir: opt.OutputDir, Extract: false, @@ -224,16 +171,18 @@ func (opt *Options) GetValueType(value string, XSDSchema []interface{}) (valueTy NSSchemaLocationMap: opt.NSSchemaLocationMap, ParseFileList: opt.ParseFileList, ParseFileMap: opt.ParseFileMap, - }).Parse() - if err != nil { + ProtoTree: make([]interface{}, 0), + }) + if parser.Parse() != nil { return } + depXSDSchema = parser.ProtoTree } valueType = getBasefromSimpleType(trimNSPrefix(value), depXSDSchema) if valueType != trimNSPrefix(value) && valueType != "" { return } - extractXSDSchema, err := NewParser(&Options{ + parser := NewParser(&Options{ FilePath: xsdFile, OutputDir: opt.OutputDir, Extract: true, @@ -241,10 +190,11 @@ func (opt *Options) GetValueType(value string, XSDSchema []interface{}) (valueTy NSSchemaLocationMap: opt.NSSchemaLocationMap, ParseFileList: opt.ParseFileList, ParseFileMap: opt.ParseFileMap, - }).Parse() - if err != nil { + ProtoTree: make([]interface{}, 0), + }) + if parser.Parse() != nil { return } - valueType = getBasefromSimpleType(trimNSPrefix(value), extractXSDSchema) + valueType = getBasefromSimpleType(trimNSPrefix(value), parser.ProtoTree) return } diff --git a/parser_test.go b/parser_test.go index 8e09c66..e12a65d 100644 --- a/parser_test.go +++ b/parser_test.go @@ -35,8 +35,9 @@ func TestParse(t *testing.T) { NSSchemaLocationMap: make(map[string]string), ParseFileList: make(map[string]bool), ParseFileMap: make(map[string][]interface{}), + ProtoTree: make([]interface{}, 0), }) - _, err = parser.Parse() + err = parser.Parse() assert.NoError(t, err) if filepath.Ext(file) == ".xsd" { srcCode := filepath.Join(goSrcDir, filepath.Base(file)+".go") diff --git a/xmlAttribute.go b/xmlAttribute.go index 79bf81f..ad1ed31 100644 --- a/xmlAttribute.go +++ b/xmlAttribute.go @@ -10,6 +10,8 @@ package xgen import "encoding/xml" +// OnAttribute handles parsing event on the attribute start elements. All +// attributes are declared as simple types. func (opt *Options) OnAttribute(ele xml.StartElement, protoTree []interface{}) (err error) { attribute := Attribute{ Optional: true, @@ -52,3 +54,11 @@ func (opt *Options) OnAttribute(ele xml.StartElement, protoTree []interface{}) ( opt.Attribute = &attribute return } + +// EndAttribute handles parsing event on the attribute end elements. +func (opt *Options) EndAttribute(ele xml.EndElement, protoTree []interface{}) (err error) { + if opt.Attribute != nil && opt.ComplexType.Len() == 0 { + opt.ProtoTree = append(opt.ProtoTree, opt.Attribute) + } + return +} diff --git a/xmlAttributeGroup.go b/xmlAttributeGroup.go index 1660e5b..8435145 100644 --- a/xmlAttributeGroup.go +++ b/xmlAttributeGroup.go @@ -10,6 +10,10 @@ package xgen import "encoding/xml" +// OnAttributeGroup handles parsing event on the attributeGroup start +// elements. The attributeGroup element is used to group a set of attribute +// declarations so that they can be incorporated as a group into complex type +// definitions. func (opt *Options) OnAttributeGroup(ele xml.StartElement, protoTree []interface{}) (err error) { attributeGroup := AttributeGroup{} for _, attr := range ele.Attr { @@ -37,3 +41,14 @@ func (opt *Options) OnAttributeGroup(ele xml.StartElement, protoTree []interface } return } + +// EndAttributeGroup handles parsing event on the attributeGroup end elements. +func (opt *Options) EndAttributeGroup(ele xml.EndElement, protoTree []interface{}) (err error) { + if ele.Name.Local == opt.CurrentEle && opt.InAttributeGroup { + opt.ProtoTree = append(opt.ProtoTree, opt.AttributeGroup) + opt.CurrentEle = "" + opt.InAttributeGroup = false + opt.AttributeGroup = nil + } + return +} diff --git a/xmlComplexType.go b/xmlComplexType.go index 0189f38..06d7252 100644 --- a/xmlComplexType.go +++ b/xmlComplexType.go @@ -10,6 +10,8 @@ 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) @@ -34,3 +36,10 @@ func (opt *Options) OnComplexType(ele xml.StartElement, protoTree []interface{}) } 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 +} diff --git a/xmlElement.go b/xmlElement.go index 449dee6..c2b8a56 100644 --- a/xmlElement.go +++ b/xmlElement.go @@ -10,6 +10,7 @@ package xgen import "encoding/xml" +// OnElement handles parsing event on the element start elements. func (opt *Options) OnElement(ele xml.StartElement, protoTree []interface{}) (err error) { e := Element{} for _, attr := range ele.Attr { @@ -59,3 +60,11 @@ func (opt *Options) OnElement(ele xml.StartElement, protoTree []interface{}) (er opt.Element.Push(&e) return } + +// EndElement handles parsing event on the element end elements. +func (opt *Options) EndElement(ele xml.EndElement, protoTree []interface{}) (err error) { + if opt.Element.Len() > 0 && opt.ComplexType.Len() == 0 { + opt.ProtoTree = append(opt.ProtoTree, opt.Element.Pop()) + } + return +} diff --git a/xmlEnumeration.go b/xmlEnumeration.go new file mode 100644 index 0000000..0039a9f --- /dev/null +++ b/xmlEnumeration.go @@ -0,0 +1,29 @@ +// Copyright 2020 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" + +// EndEnumeration handles parsing event on the enumeration end elements. +// Enumeration defines a list of acceptable values. +func (opt *Options) EndEnumeration(ele xml.EndElement, protoTree []interface{}) (err error) { + if opt.Attribute != nil && opt.SimpleType.Peek() != nil { + if opt.Attribute.Type, err = opt.GetValueType(opt.SimpleType.Pop().(*SimpleType).Base, opt.ProtoTree); err != nil { + return + } + opt.CurrentEle = "" + } + if opt.SimpleType.Len() > 0 && opt.Element.Len() > 0 { + if opt.Element.Peek().(*Element).Type, err = opt.GetValueType(opt.SimpleType.Pop().(*SimpleType).Base, opt.ProtoTree); err != nil { + return + } + opt.CurrentEle = "" + } + return +} diff --git a/xmlFractionDigits.go b/xmlFractionDigits.go new file mode 100644 index 0000000..c66095b --- /dev/null +++ b/xmlFractionDigits.go @@ -0,0 +1,25 @@ +// Copyright 2020 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" + +// EndFractionDigits handles parsing event on the fractionDigits end elements. +// Enumeration Defines a list of acceptable values. FractionDigits specifies +// the maximum number of decimal places allowed. Must be equal to or greater +// than zero. +func (opt *Options) EndFractionDigits(ele xml.EndElement, protoTree []interface{}) (err error) { + if opt.SimpleType.Len() > 0 && opt.Element.Len() > 0 { + if opt.Element.Peek().(*Element).Type, err = opt.GetValueType(opt.SimpleType.Pop().(*SimpleType).Base, opt.ProtoTree); err != nil { + return + } + opt.CurrentEle = "" + } + return +} diff --git a/xmlGroup.go b/xmlGroup.go index 33931f7..dc39baf 100644 --- a/xmlGroup.go +++ b/xmlGroup.go @@ -10,6 +10,9 @@ package xgen import "encoding/xml" +// OnGroup handles parsing event on the group start elements. The group +// element is used to define a group of elements to be used in complex type +// definitions. func (opt *Options) OnGroup(ele xml.StartElement, protoTree []interface{}) (err error) { group := Group{} for _, attr := range ele.Attr { @@ -49,3 +52,17 @@ func (opt *Options) OnGroup(ele xml.StartElement, protoTree []interface{}) (err } return } + +// EndGroup handles parsing event on the group end elements. +func (opt *Options) EndGroup(ele xml.EndElement, protoTree []interface{}) (err error) { + if ele.Name.Local == opt.CurrentEle && opt.InGroup == 1 { + opt.ProtoTree = append(opt.ProtoTree, opt.Group) + opt.CurrentEle = "" + opt.InGroup-- + opt.Group = nil + } + if ele.Name.Local == opt.CurrentEle { + opt.InGroup-- + } + return +} diff --git a/xmlImport.go b/xmlImport.go index d242c85..ed5d715 100644 --- a/xmlImport.go +++ b/xmlImport.go @@ -10,6 +10,9 @@ package xgen import "encoding/xml" +// OnImport handles parsing event on the import start elements. The list +// element defines a simple type element as a list of values of a specified +// data type. func (opt *Options) OnImport(ele xml.StartElement, protoTree []interface{}) (err error) { opt.prepareNSSchemaLocationMap(ele) return diff --git a/xmlLength.go b/xmlLength.go new file mode 100644 index 0000000..b358501 --- /dev/null +++ b/xmlLength.go @@ -0,0 +1,24 @@ +// Copyright 2020 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" + +// EndLength handles parsing event on the length end elements. Length +// specifies the exact number of characters or list items allowed. Must be +// equal to or greater than zero. +func (opt *Options) EndLength(ele xml.EndElement, protoTree []interface{}) (err error) { + if opt.SimpleType.Len() > 0 && opt.Element.Len() > 0 { + if opt.Element.Peek().(*Element).Type, err = opt.GetValueType(opt.SimpleType.Pop().(*SimpleType).Base, opt.ProtoTree); err != nil { + return + } + opt.CurrentEle = "" + } + return +} diff --git a/xmlList.go b/xmlList.go index 0ed7724..a4206f2 100644 --- a/xmlList.go +++ b/xmlList.go @@ -10,6 +10,9 @@ package xgen import "encoding/xml" +// OnList handles parsing event on the list start elements. The list element +// defines a simple type element as a list of values of a specified data +// type. func (opt *Options) OnList(ele xml.StartElement, protoTree []interface{}) (err error) { if opt.SimpleType.Peek() == nil { return @@ -17,8 +20,7 @@ func (opt *Options) OnList(ele xml.StartElement, protoTree []interface{}) (err e opt.SimpleType.Peek().(*SimpleType).List = true for _, attr := range ele.Attr { if attr.Name.Local == "itemType" { - opt.SimpleType.Peek().(*SimpleType).Base, err = opt.GetValueType(attr.Value, protoTree) - if err != nil { + if opt.SimpleType.Peek().(*SimpleType).Base, err = opt.GetValueType(attr.Value, protoTree); err != nil { return } } diff --git a/xmlMaxExclusive.go b/xmlMaxExclusive.go new file mode 100644 index 0000000..5731e99 --- /dev/null +++ b/xmlMaxExclusive.go @@ -0,0 +1,24 @@ +// Copyright 2020 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" + +// EndMaxExclusive handles parsing event on the maxExclusive end elements. +// MaxExclusive specifies the upper bounds for numeric values (the value must +// be less than this value). +func (opt *Options) EndMaxExclusive(ele xml.EndElement, protoTree []interface{}) (err error) { + if opt.SimpleType.Len() > 0 && opt.Element.Len() > 0 { + if opt.Element.Peek().(*Element).Type, err = opt.GetValueType(opt.SimpleType.Pop().(*SimpleType).Base, opt.ProtoTree); err != nil { + return + } + opt.CurrentEle = "" + } + return +} diff --git a/xmlMaxInclusive.go b/xmlMaxInclusive.go new file mode 100644 index 0000000..e5229b8 --- /dev/null +++ b/xmlMaxInclusive.go @@ -0,0 +1,24 @@ +// Copyright 2020 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" + +// EndMaxInclusive handles parsing event on the maxInclusive end elements. +// MaxInclusive specifies the upper bounds for numeric values (the value must +// be less than or equal to this value). +func (opt *Options) EndMaxInclusive(ele xml.EndElement, protoTree []interface{}) (err error) { + if opt.SimpleType.Len() > 0 && opt.Element.Len() > 0 { + if opt.Element.Peek().(*Element).Type, err = opt.GetValueType(opt.SimpleType.Pop().(*SimpleType).Base, opt.ProtoTree); err != nil { + return + } + opt.CurrentEle = "" + } + return +} diff --git a/xmlMaxLength.go b/xmlMaxLength.go new file mode 100644 index 0000000..26a55f1 --- /dev/null +++ b/xmlMaxLength.go @@ -0,0 +1,24 @@ +// Copyright 2020 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" + +// EndMaxLength handles parsing event on the maxLength end elements. MaxLength +// specifies the maximum number of characters or list items allowed. Must be +// equal to or greater than zero. +func (opt *Options) EndMaxLength(ele xml.EndElement, protoTree []interface{}) (err error) { + if opt.SimpleType.Len() > 0 && opt.Element.Len() > 0 { + if opt.Element.Peek().(*Element).Type, err = opt.GetValueType(opt.SimpleType.Pop().(*SimpleType).Base, opt.ProtoTree); err != nil { + return + } + opt.CurrentEle = "" + } + return +} diff --git a/xmlMinExclusive.go b/xmlMinExclusive.go new file mode 100644 index 0000000..fe2abd5 --- /dev/null +++ b/xmlMinExclusive.go @@ -0,0 +1,24 @@ +// Copyright 2020 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" + +// EndMinExclusive handles parsing event on the minExclusive end elements. +// MinExclusive specifies the lower bounds for numeric values (the value must +// be greater than this value). +func (opt *Options) EndMinExclusive(ele xml.EndElement, protoTree []interface{}) (err error) { + if opt.SimpleType.Len() > 0 && opt.Element.Len() > 0 { + if opt.Element.Peek().(*Element).Type, err = opt.GetValueType(opt.SimpleType.Pop().(*SimpleType).Base, opt.ProtoTree); err != nil { + return + } + opt.CurrentEle = "" + } + return +} diff --git a/xmlMinInclusive.go b/xmlMinInclusive.go new file mode 100644 index 0000000..49c1d14 --- /dev/null +++ b/xmlMinInclusive.go @@ -0,0 +1,24 @@ +// Copyright 2020 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" + +// EndMinInclusive handles parsing event on the minInclusive end elements. +// MinInclusive specifies the lower bounds for numeric values (the value must +// be greater than or equal to this value). +func (opt *Options) EndMinInclusive(ele xml.EndElement, protoTree []interface{}) (err error) { + if opt.SimpleType.Len() > 0 && opt.Element.Len() > 0 { + if opt.Element.Peek().(*Element).Type, err = opt.GetValueType(opt.SimpleType.Pop().(*SimpleType).Base, opt.ProtoTree); err != nil { + return + } + opt.CurrentEle = "" + } + return +} diff --git a/xmlMinLength.go b/xmlMinLength.go new file mode 100644 index 0000000..6338389 --- /dev/null +++ b/xmlMinLength.go @@ -0,0 +1,24 @@ +// Copyright 2020 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" + +// EndMinLength handles parsing event on the minLength end elements. MinLength +// specifies the minimum number of characters or list items allowed. Must be +// equal to or greater than zero. +func (opt *Options) EndMinLength(ele xml.EndElement, protoTree []interface{}) (err error) { + if opt.SimpleType.Len() > 0 && opt.Element.Len() > 0 { + if opt.Element.Peek().(*Element).Type, err = opt.GetValueType(opt.SimpleType.Pop().(*SimpleType).Base, opt.ProtoTree); err != nil { + return + } + opt.CurrentEle = "" + } + return +} diff --git a/xmlPattern.go b/xmlPattern.go new file mode 100644 index 0000000..bb75e45 --- /dev/null +++ b/xmlPattern.go @@ -0,0 +1,30 @@ +// Copyright 2020 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" + +// EndPattern handles parsing event on the pattern end elements. Pattern +// defines the exact sequence of characters that are acceptable. +func (opt *Options) EndPattern(ele xml.EndElement, protoTree []interface{}) (err error) { + if opt.Attribute != nil && opt.SimpleType.Peek() != nil { + opt.Attribute.Type, err = opt.GetValueType(opt.SimpleType.Pop().(*SimpleType).Base, opt.ProtoTree) + if err != nil { + return + } + opt.CurrentEle = "" + } + if opt.SimpleType.Len() > 0 && opt.Element.Len() > 0 { + if opt.Element.Peek().(*Element).Type, err = opt.GetValueType(opt.SimpleType.Pop().(*SimpleType).Base, opt.ProtoTree); err != nil { + return + } + opt.CurrentEle = "" + } + return +} diff --git a/xmlRestriction.go b/xmlRestriction.go index 11a1001..a56afd0 100644 --- a/xmlRestriction.go +++ b/xmlRestriction.go @@ -10,6 +10,9 @@ package xgen import "encoding/xml" +// OnRestriction handles parsing event on the restriction start elements. The +// restriction element defines restrictions on a simpleType, simpleContent, or +// complexContent definition. func (opt *Options) OnRestriction(ele xml.StartElement, protoTree []interface{}) (err error) { for _, attr := range ele.Attr { if attr.Name.Local == "base" { @@ -28,3 +31,15 @@ func (opt *Options) OnRestriction(ele xml.StartElement, protoTree []interface{}) } return } + +// EndRestriction handles parsing event on the restriction end elements. +func (opt *Options) EndRestriction(ele xml.EndElement, protoTree []interface{}) (err error) { + if opt.Attribute != nil && opt.SimpleType.Peek() != nil { + opt.Attribute.Type, err = opt.GetValueType(opt.SimpleType.Pop().(*SimpleType).Base, opt.ProtoTree) + if err != nil { + return + } + opt.CurrentEle = "" + } + return +} diff --git a/xmlSchema.go b/xmlSchema.go index 9b45dc2..645b997 100644 --- a/xmlSchema.go +++ b/xmlSchema.go @@ -10,6 +10,8 @@ package xgen import "encoding/xml" +// OnSchema handles parsing event on the schema start elements. Schema is the +// root element of every XML Schema. func (opt *Options) OnSchema(ele xml.StartElement, protoTree []interface{}) (err error) { opt.prepareLocalNameNSMap(ele) return diff --git a/xmlSimpleType.go b/xmlSimpleType.go index 7d469cf..71237c9 100644 --- a/xmlSimpleType.go +++ b/xmlSimpleType.go @@ -10,6 +10,9 @@ 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{}) @@ -22,3 +25,17 @@ func (opt *Options) OnSimpleType(ele xml.StartElement, protoTree []interface{}) } return } + +// EndSimpleType handles parsing event on the simpleType end elements. +func (opt *Options) EndSimpleType(ele xml.EndElement, protoTree []interface{}) (err error) { + 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 +} diff --git a/xmlTotalDigits.go b/xmlTotalDigits.go new file mode 100644 index 0000000..69ed151 --- /dev/null +++ b/xmlTotalDigits.go @@ -0,0 +1,24 @@ +// Copyright 2020 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" + +// EndTotalDigits handles parsing event on the totalDigits end elements. +// TotalDigits specifies the exact number of digits allowed. Must be greater +// than zero. +func (opt *Options) EndTotalDigits(ele xml.EndElement, protoTree []interface{}) (err error) { + if opt.SimpleType.Len() > 0 && opt.Element.Len() > 0 { + if opt.Element.Peek().(*Element).Type, err = opt.GetValueType(opt.SimpleType.Pop().(*SimpleType).Base, opt.ProtoTree); err != nil { + return + } + opt.CurrentEle = "" + } + return +} diff --git a/xmlUnion.go b/xmlUnion.go index 75b4570..e6786ec 100644 --- a/xmlUnion.go +++ b/xmlUnion.go @@ -13,6 +13,9 @@ import ( "strings" ) +// OnUnion handles parsing event on the union start elements. The union +// element defines a simple type as a collection (union) of values from +// specified simple data types. func (opt *Options) OnUnion(ele xml.StartElement, protoTree []interface{}) (err error) { opt.InUnion = true if opt.SimpleType.Peek() == nil { @@ -34,3 +37,11 @@ func (opt *Options) OnUnion(ele xml.StartElement, protoTree []interface{}) (err } return } + +// EndUnion handles parsing event on the union end elements. +func (opt *Options) EndUnion(ele xml.EndElement, protoTree []interface{}) (err error) { + if opt.SimpleType.Len() > 0 { + opt.InUnion = false + } + return +} diff --git a/xmlWhiteSpace.go b/xmlWhiteSpace.go new file mode 100644 index 0000000..c234957 --- /dev/null +++ b/xmlWhiteSpace.go @@ -0,0 +1,24 @@ +// Copyright 2020 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" + +// EndWhiteSpace handles parsing event on the whiteSpace end elements. +// WhiteSpace specifies how white space (line feeds, tabs, spaces, and +// carriage returns) is handled. +func (opt *Options) EndWhiteSpace(ele xml.EndElement, protoTree []interface{}) (err error) { + if opt.SimpleType.Len() > 0 && opt.Element.Len() > 0 { + if opt.Element.Peek().(*Element).Type, err = opt.GetValueType(opt.SimpleType.Pop().(*SimpleType).Base, opt.ProtoTree); err != nil { + return + } + opt.CurrentEle = "" + } + return +}