diff --git a/.gitignore b/.gitignore
index 7545143..81599a2 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1 +1,2 @@
/gocomply_xsd2go
+/tests/test-schemas/
diff --git a/Makefile b/Makefile
index 7190e25..afcef32 100644
--- a/Makefile
+++ b/Makefile
@@ -1,5 +1,7 @@
GO=GO111MODULE=on go
GOBUILD=$(GO) build
+XSD_TEST_DIR=./tests/xsd-examples/valid
+TEST_MODELS_DIR=./tests/test-schemas/
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
ifeq (,$(shell go env GOBIN))
@@ -8,12 +10,17 @@ else
GOBIN=$(shell go env GOBIN)
endif
+.PHONY: pkger vendor build clean all ci-update-bundled-deps check
+
all: build
-build:
+build: ci-update-bundled-deps
$(GOBUILD) ./cli/gocomply_xsd2go
-.PHONY: pkger vendor
+clean:
+ rm -f ./gocomply_xsd2go
+ rm -rf $(TEST_MODELS_DIR)
+
pkger:
ifeq ("$(wildcard $(GOBIN)/pkger)","")
go install github.com/markbates/pkger/cmd/pkger@latest
@@ -23,6 +30,14 @@ ci-update-bundled-deps: pkger
$(GOBIN)/pkger -o pkg/template
go fmt ./pkg/template
+generate-test-schemas: build $(XSD_TEST_DIR)/*.xsd
+ @for xsd in $(shell ls $(XSD_TEST_DIR)/*.xsd); do \
+ ./gocomply_xsd2go convert $${xsd} "" $(TEST_MODELS_DIR); \
+ done
+
+check: generate-test-schemas
+ $(GO) test -v -cover -coverpkg=./... -tags=xml_test ./tests
+
vendor:
$(GO) mod tidy
$(GO) mod vendor
diff --git a/pkg/template/pkged.go b/pkg/template/pkged.go
index 4ddae51..1348d86 100644
--- a/pkg/template/pkged.go
+++ b/pkg/template/pkged.go
@@ -10,4 +10,4 @@ import (
"github.com/markbates/pkger/pkging/mem"
)
-var _ = pkger.Apply(mem.UnmarshalEmbed([]byte(`1f8b08000000000000ffec195d4fe33af6af5cf9757349d2124a2aed032dd09601eed20e4d9bd168e4c44ee2a9636763a7b48cf8ef2b3b1f4da10574efc39576f7a1c4e7c3c7e7db27e117202ce202f47f01f5bb2439e80333e12936052d565090d5ef51f7d444504233c72881d28c8934932230631ef234a35b73235027e6c0009334e3b9fc179409e80360807b9862d0070dfd928725e12bcc632ccbf594f36a75076598803e2b2835c04c428a413f8254e00a9a6228382b7947fc9a502c6aeef2e406bcc459b3fe8a857cc5ad50af76dc7154a8f37e814afd98c8a4084e429e1e30f40e1206fa322fb0f1577d36e2771cfd690166cc4f528eb49c39ce05d1feb14fec73f0f2f26280a834fbd73be6f4cd6c159b12a71985129b729b617122d38caa6d2a3bd413610909d5925819d4169f010479c6a06f3ba73d03a41c61d03fed587af94312cddeb13adddf6dfbf78ef5d5b6fbb6d5b7ba27d6e979cf75ec9efb0fcbee5b163000113f9072671575b1d5275ee235e89f9df67ab601268c83be7de6f61cf7ecdc00f794b015e8db3a8018f4bb5dfbfcdc008f0481be6d59960146bbe5e2c78f0c220bf42d034c91126a1960d6527d4057a525a7967ba6401eae04e89f1be0429254a932c321e8db3dcb3aed3996d535c0bd509833bbe73a9675f66280bbf7396b935f0c30fc34e7e2c78f82150223d0ff661996617dd7c14d70fe578b762ff6af2bf878cebcde56157a0bf35ea9ffe95aa91ac4377002be371da2acc2fd06111484a2df2697bfa544a47a53ab637c6bf43c89b912d4b4826f20d84a2c8001a25402e323076c04da674a61be0aa0c4429171ae88dc8c789e42258d7093f0421255305c1d92419998aa42d5021840e28ddc79f57bddc6be81a08888b2bfd64ea9926321cca8f27683889f49a66126216138372911b242e08d5ee5db4cf26661c252620984244bb4de158cda4424e00ec0214af6a03d22ea388eedb61094924c9270874952d88208933867909a9012280ee00312976dee0d81e784c5470966109077a8e22011a3279823f1ca8683643322981ed28b1121f1210b4b821911280f5073c8509522152945ce0e50e416149eb68076004402ed3da8e39cedc18edd69c1452029dec192b642b0712c771f32b315d90003e034c04a1bcc428eca20d44b130a66b7e1000a7c76ba87210ce6db3626c19b36f85395720bce70da0637a97212ce739e1f29d8a0882248b999e01cff89622690859ce2143253c83c84027f58ec4789077478cdd1a4400a33f13e6bb68a4b777fc8630a8974ab89b909752388b9a99ba3197226640e09abb0888766c8d314d788a66fc5adfc54b77e067398564233988bbad165b9662b011142c66a40f215667a49218b4f781e9b1b936169265247f120de8492a7478961a24e96afe9ba85b612f238514b4861f63e933a8b30a433f31db6da3f9fe33209c24c928854fe39bae127cc20c365e21de75af11cc337eedde71124cda83a118509f958a4cc2122927006e9a7f80b4642357f1d626aac568402c69fe452c998c1f0708477f9080f47b961286474fe6e74ded52a2f1816072932874ca812010648a048aa8719e66157b5d6dd8d169036a8ae7048e3362ae46b9c2b8b7319f2f51e252bda60944ac173d946c51ce67aba6961100e8a781f853719ce4955db2dbcee0dbbb4d48b3d8ce4b00d332c650e43dcc671a19b701b95714adbf0eb2d398e280e2525720f2d60845be3d00e4f584c7144499cece92fb62284949a788343ccd6874805d357d52e5fb09094ef79a760eadc0443a4cb510f5a849b917835b295dbd25237f530cbd1a25a4a51afab4b3a552f3ee5c34c0b2a490675ec34e2df059718e98e09037df732ddcccafe26b3d652ffa9bdde205b39fd066742111252511896a416a73237cbb91eff145ce4cd2cca85766335951e184eab98e9558c3759b330c59649a8bc9c174c9646572b33d4637b0dedf4933cd5c3e01b4ae5de3778f5267818adc2acde40cbc2503735d7a920a49af0d42eb16561f5d89dbcdb5996330c9e7252de5efb63f82bb8bcf114b6b474d7f9aa95ea38f6d93e7cae419566c0006bcc10cfcdbd96528fdf090c13d8b13ec79571bab5bb96f301b77ea8b6f359be7a787b873959a1e87d8e3713fd67783fb048a52c6242fd522c44d9b48f3136a51317f2d8f97b7c59ce37db0f183b6692c170f50e17410c1e218bada83afa21aace3281c322c7664010c90b7accbc3717d051a63a0795c0cff03125effbfff237b3aaff299b56f14726559f3d8e7e407b3180d207f4c1edf63c7ee8b82b7f3660bee7d030bdb67cef215eb2550cc7532b1cdf9ddd6e5d0617538ebc49b1ecb8f2b683d6ea198e36ce6d3779f62f6f58f02ce2e9d579fc75e53e4eaee657b3f9433124e7ebc995bdf64773116e0769d09dc4b82be25b3a4dc2145174e52481377f0e47d73ffdd9c08d1eb2a7a5779f2f3d442763d99b0c9d71600f926547267e67fec7d2b3e9646cbbc338cb82c5601db287f8cb058f27c30b25574ec637499022aaf759548623778bc6f77ff8de7ce57b53377a2879cbdf4d0f6f2f0a256f12b7648ce6853f54baf06c18673ddc6d645ee3b13a739a2cd30d9d7a1b1a78f3028defe268617d990c2fd6b7dbc175309a4bdf73ac21b988d1983ef9b3813e67da711bfd27e37b2b64f39f6838e829bec970b0fcfab8a9e8890c864eb91e0d4e03efe96cc264ef76a57de546b39bb8dad3c3dbc176e939cc9f5d140f8ba915a694a0c59486dbc1beadb52f2d25e351e9ab6c553a8d82ee0d851e2abe7aee0a791b1a2dec1ede2abf4f9d70a4ce1bc478648b3f88f297b30cbc52cf6861092543ed839e9ff98b9be768619165130f4983f441fbe690be07fc57c720be5da1f534a534184debb36a7def7dcfbe5b2ee81a2da66eb4507e51bceed6f7280b56f6da1fcf85bfb0dd5ace5cc5e07167f752f9f7921325cf1bd9e26b7a2d15ff24bdf8d2f86a97030dee7636c87c72513c74dc028daeb380dd3ffa8bc4d2f9482a3f5f4f291e3fc46177ba859ec39af891cd4f38badefaa36b6bb9173f2bf63d6755da3f7075be75e685af739c7f51b5e95ddf5f4daeeed7c16220fc45f28817033a194de9b2b34954ad42cf2dc2a7e379fa50d629c5d73a9ecfb5be9fcdcdb226683a19396b34bc2866a3ebe7c66f8fd7161adf644b36b7cafa2d63ef5dd9779a3ed3f6177aad68a51f699056b5a87cbdabd9011a2bbfddd8a8a5e7df92bf63d95371297bcd1b3d9b1a6fd7d9df9bb78376de7c325f07157caffa46e16f6b3f4dc4b29324613a4dd0e8aaf1c7ebb81d907f13a40e0da9ea5f3bbfcc3ca7f01737cbc07b3a541799dec3d49eb22e9a1e5ce9193decd584eab1cb47eb217eec509dd7f3328f57be772f968b9b048de83a60775f7057ee7acd22790aba37d6d2bb11fefc3ed3b534ff6c3dd4f790e66fdd41555e0ca7cfd0b39f82d1bcaccd4bee4e86a7554f7bddf31c3b58d4fd6ef033e838cf48f35cacc23d7b76b97ebb2875b89d1dd26bff6c953755ddb9d1ecc2adefb8265f347eb2cb97aac795bd5ac7f69ffa052b57efe3cda4b19b2740fddf1dfcffffc9feb7cd972fff010000ffff010000ffff46ff9a54721f0000`)))
+var _ = pkger.Apply(mem.UnmarshalEmbed([]byte(`1f8b08000000000000ffec595b6fe23c9fff2aaf7cbbbccd014209d25e143a053a6d9fa7b425c06834726c937870ec6cec50e8a8df7d65e74068a1edb357abd56ad4c9fff0b3fd3fc769ff00ca574282fe1fa07f2e6906fac07a922493d66fb8ce438b724cb6182a686d257623015a6092a422537f4315833e002d70071302faa0d65f0a54281e61161155d053214aea162a14833ecf196b8107051901fd15649294dc94402978811d892bca88acd0c5c9357b49d29a7e2452bd416bd19b15b702e7fabc3fa0343fa22acec33324122b12482429dbed1dbd859483beca72d2fa626846e256e0cf705624ce12810d7c4632498db7ce99d303afafaf2db02a9cf8f381717d2b5d47962249caa02296daa5449ea924657a994ea97e62a2206566275ea4a8816b01495f08e83b5ecf6f81446002fa9d76d790bf143570d7763bffb63bffb67b8faed3f7dcbedd3bf35cb7e3763addffb0ddbe6d8316a0f217d6b129532877e6c04bb2017da77b7e7eeeb63b26ee04f4db6dd7eeb4c01da37c0dfa4e0b4cb8007dc7f5dbe7bd4ea7d7024f1483be673b2d30d2946bb7c014eb9dec16f81be25f2812bf6cd0ff61b7ccbf9f2d70a14d952941fad007fd70ce9db6dbedf5bafa24a925edaee3743dbffbda02b7c7e06ed7f67cb757c12b0fedd71618fe43fc80662a3ebac6b3db9eebd4269dfb3dbbebface6b0b3c34f2306002ad25e8f734b92e32d4b1fd6e0b5c311849138811e1e6792353981143de97a40ecc4f534331c9bed8d00795f4b6bb4f57e0db65e51068483e1a039ff55139237e8033f0b31e1245231ece8830a70cff6b72f9af84cac42c6a0c8d1fb5396791d01bd5d3e00708778a48d002ab4481d6677e6e253e0425305b875011a9d524d34a61ad449640bd1b151615b9a2bacb843e24852ab6745b6b02b480225bb50fdecf6a92fd0061bea2daffca3a94a4fa7f91a41991d25a95a1ad05d10b2d005c41ca4966312a5529205b4365bb54899ab060b16fc1209ac6c6fa92c74d259670cf1084e303ee40895dcf73fc8680319a2a8af69238810d8e7245320e99051985f2883ca4513121df294446797452618521fd402b8f2a097e8619966f7c38aab65694b06376712a1539e661a1b05614aa23da0c725c164aa94ab0b767b4bac1a14e83692640c6d039e05caf7bc07b8edbe0f35031b2e7156ba460ebd9fe21b7b7368148bc815ae99a6e410b902424da54c291c045862ad282923b4d3e8492743b0712ca61b66b4a62b26db2bf75b737f894244d769be808922c13d9899e0ef3d50a3261c52423ff837ea79023c14802b9255586a0249fce8393ca2336bc4534229eca8fa1e93a2ac2fd29c6920a9bf445c282664a44c232f3d342824b9541ca4b2916c84222494825a8475bd4285e7d9b4861069372d31466b29a85696660052311e4bc629458136e4806797426b2c8da5a9c282b56268b47e516542239a944b13e59bdd59b29db28c8d34ab34302d38f41fa2cf3aefa1856c5e76b288b62c2155dd1323e2717fc8629e4a428bcd3a8b5c8087c17de438ca449caf48918c5f4f32d550631555470c8be84cf3945faba770c547bad15398cbe88d2c59842743cc3fb7a84c7b35c0372b5ea7d989d0fadca724ee4518dca2097ba45400bc450c6e5c342196aebb9bb7fdd85b4c9865412e3d45eb25304b2a82942314431ec95af82bd586c48a64393292436079a346fb2ab4449911d9c120998999b5243824998474744f25046b629c96839181a7271802b88038912b0c973a254061169ca843413bc294a05634dfeed928cac18418a5175209670451ad7adbd9cf2889115a3517c60bfdc490419b3c89620c237c7543937efb97db111a998388858cef5b93181d8f4b2b9c85161ade49b2b61b18c8983519114a6ea8755dc614a52c98a2e4b20d11f67c5c34a72a6680a4d7a8de0bf72a10836d31786e625cfcd602c66a54a1ba4f9af4a422d6c98f44e664189282d359c285a6da7bb20cd84b9676a3ecfeaabaf9026aae525f8c85db84ca1a122b24d6bc2923baea00e7a967355385d5216325f0915b7b74f89c4dc3adf69caf0be93ebcfd516908c22d3db65a7e877bc30752095be381ad58ea3f2b13fa7ac8efa4a0fc3e78c16efbdc33bfe1bbe78576a69e1d77e6696949e554ef790ef1956d71868810de15864d6c130aa6ef56662b8f6d750a9603ba76d7b9fa0cd438fa7afe2aa6bdf07e0788d571f23de7d287c05fb8947ba403197fa27215216e3fe14b06e942857a7ce3fc0a599d8ee3e01ba569c42b4fe004531871fa833919f4c84a93349509e112ba4986639fb10da7c799d045555a837fc0a8eebfd7efedff9ad5c39bdb485ebe83303cb5f859cfc15dd6b0be873411fdcec7ad1bdebaf970f03be0c3c86922b7b19dc470bbe8ee0786aa3f16df766e773389f0a1c4cf285ebab1b176ff4138db6de4d3b7e595e5ef3f04546d36fbde871ed3f4dbecdbe3dcceef321ed6d26df9ccd723493683748c2f624226d19ddb0698c12ccf0372f0e83d90b1a5dfd5e3e0cfcd57dfabc08eeb24580d964acce27436f1c3a8378e1aa78e9cefe5a040e9b8c1d7f18a569381f6c10bf8fbe5f886832bcd0fbaac9f83a0e13cccc3a9b2934f277787cf7d73298ad97c1d45fdd17d8e2e7fa9cec2e72bddf246aec319ae5cba1b645a4c3283d27ed7acf2b32d6674ee345b265d360cbc26096e3f16db49adbdf27c38bcdcd6e70158e666a1978f6905e4478cc9e970f0373ced4f56bfb27e33b1bf1d96f3c1c9c6bdc6438583c3e6d4b7dacc2a157d0a341270c9ebb13aece6fd62656fe6aae691d5396c060b6436dc79f2417df8d4f3a66fb180cf078ba83c1b58347b31713377a51fb6ff2b0c69bc7e44a99d81b3b75dc961b94ccd2a5ebdd85eed40947d5997833d3fecc1dffc02e16abf05b69dbc356efa1d7a5cb8431c4effcd5c37554fa784edc3ab6c7ecad6387768346aeeaf88d603093cbfaacca5e87854fdb9804be83c78e4fdad260c3f6358301ce1f037f8d832d5bcd9d6a9f27321fb086df111939f22faaebc15b8441918702ff812fbb010b937b93fbbdcc8e60b0886ed6779b904f6318782fb3d1ac838707fe3c2de7b16d6a2061f972579d3f910b378e51328df1e81b5d5cbca9c9327f3a76a4ad5898987afe6e7aec2a7e9c0e0797a1eb3c87a3596756d4dd7a19dcc9c5fc3ac623b609f9ad5eb75b041e5f3e5ce4d379fc1cb6afed45702d974f779b703e90cb796c6253c77f3cf5d0e8e958adbce0f1b5b368df47e459983cde3c0cd2251de461fb3eba59c73172eaba68d4e153d52bd1e42abe7b34fa27e37f51df4fdfab382e036f5d604dac6bbbefe7531d378ae75376a24e1a7d56d4ed34f177cb80f150f7cd7826750d977562fc5dcded68a1fbee52502d0f468e34bece1dff667caadfded6f3a19d47e64354cf347b992e83edba3aa3b2f33198a9c7d19517b66776597f27fbb1988d3a3ffbb978b22f4fce8cd20733539b79bcc8ef5d3fc7a3ab34e47765bd56f3e31fd46fb15f55aba7f6bf0e138f216d6fa34f1e022f5fceaf1761f01ca1b6ae1f8fd7fed16d6ad670bda6e8c9f77d92367dd3b379f164df474fae7e2f6cd93fee91d95d6a7a6466625ecfd3d333fe788eaa384f86d31718987e353538b914fe64d8898ed5fc34f09c705ed5d1e077e87a2fb8a8f7353af047d74bd15337555d3d1cb3ebf0ecc3debef0ab7763dd07463e7957f38d39f49fe6b32ad31fe5f50d657f0f01d51f84c8ffff89f77fc565f2f5bf010000ffff010000ffff14ced2f5761f0000`)))
diff --git a/pkg/template/types.tmpl b/pkg/template/types.tmpl
index d05edf1..9a62f89 100644
--- a/pkg/template/types.tmpl
+++ b/pkg/template/types.tmpl
@@ -11,13 +11,13 @@ import (
{{range .ExportableElements }}
// Element
type {{ .GoName }} struct {
- XMLName xml.Name `xml:"{{.Name}}"`
+ XMLName xml.Name `xml:"{{.Name}}{{.Modifiers}}"`
{{ range .Attributes }}
{{ .GoName }} {{.GoForeignModule}}{{.GoType}} `xml:"{{.XmlName}},{{.Modifiers}}"`
{{end }}
{{ range .Elements }}
- {{ .GoFieldName}} {{.GoMemLayout}}{{.GoForeignModule}}{{ .GoTypeName }} `xml:"{{.XmlName}}"`
+ {{ .GoFieldName}} {{.GoMemLayout}}{{.GoForeignModule}}{{ .GoTypeName }} `xml:"{{.XmlName}}{{.Modifiers}}"`
{{ end }}
{{- if .ContainsText }}
@@ -39,7 +39,7 @@ import (
{{end }}
{{ range .Elements }}
- {{ .GoFieldName}} {{.GoMemLayout}}{{.GoForeignModule}}{{ .GoTypeName }} `xml:"{{.XmlName}}"`
+ {{ .GoFieldName}} {{.GoMemLayout}}{{.GoForeignModule}}{{ .GoTypeName }} `xml:"{{.XmlName}}{{.Modifiers}}"`
{{end}}
{{- if .ContainsText }}
diff --git a/pkg/xsd/attribute.go b/pkg/xsd/attribute.go
index fc23b16..4f7ffe4 100644
--- a/pkg/xsd/attribute.go
+++ b/pkg/xsd/attribute.go
@@ -82,7 +82,7 @@ func (a *Attribute) XmlName() string {
}
func (a *Attribute) optional() bool {
- return a.Use == "optional"
+ return a.Use == "" || a.Use == "optional"
}
func (a *Attribute) compile(s *Schema) {
diff --git a/pkg/xsd/element.go b/pkg/xsd/element.go
index 9b93839..b3f572f 100644
--- a/pkg/xsd/element.go
+++ b/pkg/xsd/element.go
@@ -98,6 +98,18 @@ func (e *Element) GoForeignModule() string {
return ""
}
+func (e *Element) Modifiers() string {
+ res := ""
+ if e.optional() {
+ res += ",omitempty"
+ }
+ return res
+}
+
+func (e *Element) optional() bool {
+ return e.MinOccurs == "0"
+}
+
func (e *Element) XmlName() string {
if e.XmlNameOverride != "" {
return e.XmlNameOverride
diff --git a/tests/xml-examples/complex.xsd.1.xml b/tests/xml-examples/complex.xsd.1.xml
new file mode 100644
index 0000000..b64fcc2
--- /dev/null
+++ b/tests/xml-examples/complex.xsd.1.xml
@@ -0,0 +1,4 @@
+
+ 1
+ 2
+
diff --git a/tests/xml-examples/complex.xsd.2.xml b/tests/xml-examples/complex.xsd.2.xml
new file mode 100644
index 0000000..7b1a54a
--- /dev/null
+++ b/tests/xml-examples/complex.xsd.2.xml
@@ -0,0 +1,4 @@
+
+ 1
+ 2
+
diff --git a/tests/xml-examples/complex.xsd.3.xml b/tests/xml-examples/complex.xsd.3.xml
new file mode 100644
index 0000000..db17cf2
--- /dev/null
+++ b/tests/xml-examples/complex.xsd.3.xml
@@ -0,0 +1,5 @@
+
+ 1
+ 2
+ 3
+
diff --git a/tests/xml_test.go b/tests/xml_test.go
new file mode 100644
index 0000000..84315c9
--- /dev/null
+++ b/tests/xml_test.go
@@ -0,0 +1,45 @@
+//go:build xml_test
+
+package tests
+
+import (
+ "encoding/xml"
+ "os"
+ "testing"
+
+ "github.com/stretchr/testify/assert"
+
+ "github.com/gocomply/xsd2go/tests/test-schemas/complex"
+)
+
+func TestMarshalComplex(t *testing.T) {
+ var v complex.Myelement
+ assertMarshal(&v, "xml-examples/complex.xsd.1.xml", t)
+ var z complex.Myelement
+ assertMarshal(&z, "xml-examples/complex.xsd.2.xml", t)
+ var x complex.Myelement
+ assertMarshal(&x, "xml-examples/complex.xsd.3.xml", t)
+}
+
+func assertMarshal(v any, xmlPath string, t *testing.T) {
+ //unmarshal xml file into v
+ in, err := os.ReadFile(xmlPath)
+ if err != nil {
+ t.Fatalf("Failure opening test file: %v", err)
+ }
+ err = xml.Unmarshal(in, v)
+ if err != nil {
+ t.Fatalf("Failure parsing test file: %v", err)
+ }
+ //marshal v into buff and compare
+ out, err := xml.MarshalIndent(v, "", " ")
+ out = append(out, '\n')
+ if err != nil {
+ t.Fatalf("Failure marshalling output: %v", err)
+ }
+ expected, err := os.ReadFile(xmlPath)
+ if err != nil {
+ t.Fatalf("Failure reading result file: %v", err)
+ }
+ assert.Equal(t, string(expected), string(out))
+}
diff --git a/tests/xsd-examples/valid/complex.xsd b/tests/xsd-examples/valid/complex.xsd
index ea5ef6e..55d383c 100644
--- a/tests/xsd-examples/valid/complex.xsd
+++ b/tests/xsd-examples/valid/complex.xsd
@@ -1,7 +1,7 @@
-
+ xmlns:complex="https://simple.example.com/" targetNamespace="https://simple.example.com/" elementFormDefault="qualified">
+
diff --git a/tests/xsd-examples/valid/complex.xsd.out b/tests/xsd-examples/valid/complex.xsd.out
index 3b094e3..d39aa37 100644
--- a/tests/xsd-examples/valid/complex.xsd.out
+++ b/tests/xsd-examples/valid/complex.xsd.out
@@ -1,6 +1,6 @@
// Code generated by https://github.com/gocomply/xsd2go; DO NOT EDIT.
// Models for https://simple.example.com/
-package simple_schema
+package complex
import (
"encoding/xml"
@@ -12,13 +12,13 @@ type Myelement struct {
Id int64 `xml:"id"`
- ExternalId *int64 `xml:"external_id"`
+ ExternalId *int64 `xml:"external_id,omitempty"`
- Id1 *int `xml:"id_1"`
+ Id1 *int `xml:"id_1,omitempty"`
- Id21 *int `xml:"id_21"`
+ Id21 *int `xml:"id_21,omitempty"`
- Id22 *int `xml:"id_22"`
+ Id22 *int `xml:"id_22,omitempty"`
}
// XSD ComplexType declarations
@@ -28,13 +28,13 @@ type MyElementType struct {
Id int64 `xml:"id"`
- ExternalId *int64 `xml:"external_id"`
+ ExternalId *int64 `xml:"external_id,omitempty"`
- Id1 *int `xml:"id_1"`
+ Id1 *int `xml:"id_1,omitempty"`
- Id21 *int `xml:"id_21"`
+ Id21 *int `xml:"id_21,omitempty"`
- Id22 *int `xml:"id_22"`
+ Id22 *int `xml:"id_22,omitempty"`
}
// XSD SimpleType declarations
diff --git a/tests/xsd-examples/valid/restriction.xsd b/tests/xsd-examples/valid/restriction.xsd
index 5df8c98..7e049f8 100644
--- a/tests/xsd-examples/valid/restriction.xsd
+++ b/tests/xsd-examples/valid/restriction.xsd
@@ -1,8 +1,8 @@
+ xmlns:restriction="https://simple.example.com/" targetNamespace="https://simple.example.com/" elementFormDefault="qualified">
-
+
@@ -105,26 +105,26 @@
-
+
-
+
-
+
-
+
-
+
-
+
diff --git a/tests/xsd-examples/valid/restriction.xsd.out b/tests/xsd-examples/valid/restriction.xsd.out
index 1451847..565c716 100644
--- a/tests/xsd-examples/valid/restriction.xsd.out
+++ b/tests/xsd-examples/valid/restriction.xsd.out
@@ -1,6 +1,6 @@
// Code generated by https://github.com/gocomply/xsd2go; DO NOT EDIT.
// Models for https://simple.example.com/
-package simple_schema
+package restriction
import (
"encoding/xml"
diff --git a/tests/xsd-examples/valid/simple-8859-1.xsd b/tests/xsd-examples/valid/simple-8859-1.xsd
index 581ef0a..112b53e 100644
--- a/tests/xsd-examples/valid/simple-8859-1.xsd
+++ b/tests/xsd-examples/valid/simple-8859-1.xsd
@@ -1,15 +1,17 @@
-
+
-
- Documentation with a character from ISO-8859-1 encoding: ñ
-
+
+
+ Documentation with a character from ISO-8859-1 encoding: ñ
+
+
diff --git a/tests/xsd-examples/valid/simple-8859-1.xsd.out b/tests/xsd-examples/valid/simple-8859-1.xsd.out
index f78fa15..3464d53 100644
--- a/tests/xsd-examples/valid/simple-8859-1.xsd.out
+++ b/tests/xsd-examples/valid/simple-8859-1.xsd.out
@@ -1,6 +1,6 @@
// Code generated by https://github.com/gocomply/xsd2go; DO NOT EDIT.
// Models for https://simple.example.com/
-package simple_schema
+package simple_8859_1
import (
"encoding/xml"
diff --git a/tests/xsd-examples/valid/simple.xsd b/tests/xsd-examples/valid/simple.xsd
index 4574892..b52984d 100644
--- a/tests/xsd-examples/valid/simple.xsd
+++ b/tests/xsd-examples/valid/simple.xsd
@@ -1,9 +1,9 @@
-
+
diff --git a/tests/xsd-examples/valid/simple.xsd.out b/tests/xsd-examples/valid/simple.xsd.out
index f78fa15..de0fae9 100644
--- a/tests/xsd-examples/valid/simple.xsd.out
+++ b/tests/xsd-examples/valid/simple.xsd.out
@@ -1,6 +1,6 @@
// Code generated by https://github.com/gocomply/xsd2go; DO NOT EDIT.
// Models for https://simple.example.com/
-package simple_schema
+package simple
import (
"encoding/xml"
diff --git a/tests/xsd-examples/valid/xmldsig-core-schema.xsd.out b/tests/xsd-examples/valid/xmldsig-core-schema.xsd.out
index 9730362..48693b6 100644
--- a/tests/xsd-examples/valid/xmldsig-core-schema.xsd.out
+++ b/tests/xsd-examples/valid/xmldsig-core-schema.xsd.out
@@ -16,9 +16,9 @@ type Signature struct {
SignatureValue SignatureValueType `xml:"SignatureValue"`
- KeyInfo *KeyInfoType `xml:"KeyInfo"`
+ KeyInfo *KeyInfoType `xml:"KeyInfo,omitempty"`
- Object []ObjectType `xml:"Object"`
+ Object []ObjectType `xml:"Object,omitempty"`
}
// Element
@@ -56,7 +56,7 @@ type SignatureMethod struct {
Algorithm string `xml:"Algorithm,attr"`
- HmacoutputLength *HmacoutputLengthType `xml:",any"`
+ HmacoutputLength *HmacoutputLengthType `xml:",any,omitempty"`
}
// Element
@@ -69,7 +69,7 @@ type Reference struct {
Type string `xml:"Type,attr,omitempty"`
- Transforms *TransformsType `xml:"Transforms"`
+ Transforms *TransformsType `xml:"Transforms,omitempty"`
DigestMethod DigestMethodType `xml:"DigestMethod"`
@@ -89,7 +89,7 @@ type Transform struct {
Algorithm string `xml:"Algorithm,attr"`
- Xpath []string `xml:"XPath"`
+ Xpath []string `xml:"XPath,omitempty"`
}
// Element
@@ -112,19 +112,19 @@ type KeyInfo struct {
Id string `xml:"Id,attr,omitempty"`
- KeyName []string `xml:"KeyName"`
+ KeyName []string `xml:"KeyName,omitempty"`
- KeyValue []KeyValueType `xml:"KeyValue"`
+ KeyValue []KeyValueType `xml:"KeyValue,omitempty"`
- RetrievalMethod []RetrievalMethodType `xml:"RetrievalMethod"`
+ RetrievalMethod []RetrievalMethodType `xml:"RetrievalMethod,omitempty"`
- X509Data []X509DataType `xml:"X509Data"`
+ X509Data []X509DataType `xml:"X509Data,omitempty"`
- Pgpdata []PgpdataType `xml:"PGPData"`
+ Pgpdata []PgpdataType `xml:"PGPData,omitempty"`
- Spkidata []SpkidataType `xml:"SPKIData"`
+ Spkidata []SpkidataType `xml:"SPKIData,omitempty"`
- MgmtData []string `xml:"MgmtData"`
+ MgmtData []string `xml:"MgmtData,omitempty"`
}
// Element
@@ -145,44 +145,44 @@ type MgmtData struct {
type KeyValue struct {
XMLName xml.Name `xml:"KeyValue"`
- DsakeyValue *DsakeyValueType `xml:"DSAKeyValue"`
+ DsakeyValue *DsakeyValueType `xml:"DSAKeyValue,omitempty"`
- RsakeyValue *RsakeyValueType `xml:"RSAKeyValue"`
+ RsakeyValue *RsakeyValueType `xml:"RSAKeyValue,omitempty"`
}
// Element
type RetrievalMethod struct {
XMLName xml.Name `xml:"RetrievalMethod"`
- Uri string `xml:"URI,attr"`
+ Uri string `xml:"URI,attr,omitempty"`
Type string `xml:"Type,attr,omitempty"`
- Transforms *TransformsType `xml:",any"`
+ Transforms *TransformsType `xml:",any,omitempty"`
}
// Element
type X509Data struct {
XMLName xml.Name `xml:"X509Data"`
- X509IssuerSerial *X509IssuerSerialType `xml:"X509IssuerSerial"`
+ X509IssuerSerial *X509IssuerSerialType `xml:"X509IssuerSerial,omitempty"`
- X509Ski string `xml:"X509SKI"`
+ X509Ski string `xml:"X509SKI,omitempty"`
- X509SubjectName string `xml:"X509SubjectName"`
+ X509SubjectName string `xml:"X509SubjectName,omitempty"`
- X509Certificate string `xml:"X509Certificate"`
+ X509Certificate string `xml:"X509Certificate,omitempty"`
- X509Crl string `xml:"X509CRL"`
+ X509Crl string `xml:"X509CRL,omitempty"`
}
// Element
type Pgpdata struct {
XMLName xml.Name `xml:"PGPData"`
- PgpkeyId string `xml:"PGPKeyID"`
+ PgpkeyId string `xml:"PGPKeyID,omitempty"`
- PgpkeyPacket string `xml:"PGPKeyPacket"`
+ PgpkeyPacket string `xml:"PGPKeyPacket,omitempty"`
}
// Element
@@ -234,11 +234,11 @@ type SignatureProperty struct {
type DsakeyValue struct {
XMLName xml.Name `xml:"DSAKeyValue"`
- G *CryptoBinary `xml:"G"`
+ G *CryptoBinary `xml:"G,omitempty"`
Y CryptoBinary `xml:"Y"`
- J *CryptoBinary `xml:"J"`
+ J *CryptoBinary `xml:"J,omitempty"`
}
// Element
@@ -261,9 +261,9 @@ type SignatureType struct {
SignatureValue SignatureValueType `xml:"SignatureValue"`
- KeyInfo *KeyInfoType `xml:"KeyInfo"`
+ KeyInfo *KeyInfoType `xml:"KeyInfo,omitempty"`
- Object []ObjectType `xml:"Object"`
+ Object []ObjectType `xml:"Object,omitempty"`
}
type SignatureValueType struct {
@@ -299,7 +299,7 @@ type SignatureMethodType struct {
Algorithm string `xml:"Algorithm,attr"`
- HmacoutputLength *HmacoutputLengthType `xml:",any"`
+ HmacoutputLength *HmacoutputLengthType `xml:",any,omitempty"`
InnerXml string `xml:",innerxml"`
}
@@ -313,7 +313,7 @@ type ReferenceType struct {
Type string `xml:"Type,attr,omitempty"`
- Transforms *TransformsType `xml:"Transforms"`
+ Transforms *TransformsType `xml:"Transforms,omitempty"`
DigestMethod DigestMethodType `xml:"DigestMethod"`
@@ -331,7 +331,7 @@ type TransformType struct {
Algorithm string `xml:"Algorithm,attr"`
- Xpath []string `xml:"XPath"`
+ Xpath []string `xml:"XPath,omitempty"`
InnerXml string `xml:",innerxml"`
}
@@ -349,19 +349,19 @@ type KeyInfoType struct {
Id string `xml:"Id,attr,omitempty"`
- KeyName []string `xml:"KeyName"`
+ KeyName []string `xml:"KeyName,omitempty"`
- KeyValue []KeyValueType `xml:"KeyValue"`
+ KeyValue []KeyValueType `xml:"KeyValue,omitempty"`
- RetrievalMethod []RetrievalMethodType `xml:"RetrievalMethod"`
+ RetrievalMethod []RetrievalMethodType `xml:"RetrievalMethod,omitempty"`
- X509Data []X509DataType `xml:"X509Data"`
+ X509Data []X509DataType `xml:"X509Data,omitempty"`
- Pgpdata []PgpdataType `xml:"PGPData"`
+ Pgpdata []PgpdataType `xml:"PGPData,omitempty"`
- Spkidata []SpkidataType `xml:"SPKIData"`
+ Spkidata []SpkidataType `xml:"SPKIData,omitempty"`
- MgmtData []string `xml:"MgmtData"`
+ MgmtData []string `xml:"MgmtData,omitempty"`
InnerXml string `xml:",innerxml"`
}
@@ -369,9 +369,9 @@ type KeyInfoType struct {
type KeyValueType struct {
XMLName xml.Name
- DsakeyValue *DsakeyValueType `xml:"DSAKeyValue"`
+ DsakeyValue *DsakeyValueType `xml:"DSAKeyValue,omitempty"`
- RsakeyValue *RsakeyValueType `xml:"RSAKeyValue"`
+ RsakeyValue *RsakeyValueType `xml:"RSAKeyValue,omitempty"`
InnerXml string `xml:",innerxml"`
}
@@ -379,25 +379,25 @@ type KeyValueType struct {
type RetrievalMethodType struct {
XMLName xml.Name
- Uri string `xml:"URI,attr"`
+ Uri string `xml:"URI,attr,omitempty"`
Type string `xml:"Type,attr,omitempty"`
- Transforms *TransformsType `xml:",any"`
+ Transforms *TransformsType `xml:",any,omitempty"`
}
type X509DataType struct {
XMLName xml.Name
- X509IssuerSerial *X509IssuerSerialType `xml:"X509IssuerSerial"`
+ X509IssuerSerial *X509IssuerSerialType `xml:"X509IssuerSerial,omitempty"`
- X509Ski string `xml:"X509SKI"`
+ X509Ski string `xml:"X509SKI,omitempty"`
- X509SubjectName string `xml:"X509SubjectName"`
+ X509SubjectName string `xml:"X509SubjectName,omitempty"`
- X509Certificate string `xml:"X509Certificate"`
+ X509Certificate string `xml:"X509Certificate,omitempty"`
- X509Crl string `xml:"X509CRL"`
+ X509Crl string `xml:"X509CRL,omitempty"`
}
type X509IssuerSerialType struct {
@@ -411,9 +411,9 @@ type X509IssuerSerialType struct {
type PgpdataType struct {
XMLName xml.Name
- PgpkeyId string `xml:"PGPKeyID"`
+ PgpkeyId string `xml:"PGPKeyID,omitempty"`
- PgpkeyPacket string `xml:"PGPKeyPacket"`
+ PgpkeyPacket string `xml:"PGPKeyPacket,omitempty"`
}
type SpkidataType struct {
@@ -463,11 +463,11 @@ type SignaturePropertyType struct {
type DsakeyValueType struct {
XMLName xml.Name
- G *CryptoBinary `xml:"G"`
+ G *CryptoBinary `xml:"G,omitempty"`
Y CryptoBinary `xml:"Y"`
- J *CryptoBinary `xml:"J"`
+ J *CryptoBinary `xml:"J,omitempty"`
}
type RsakeyValueType struct {