Skip to content

Commit b22e130

Browse files
committed
add support for XSD schema without explicit targetNamespace definition
Fixes: #15
1 parent 836aeb0 commit b22e130

File tree

4 files changed

+45
-1
lines changed

4 files changed

+45
-1
lines changed

pkg/xsd/schema.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"encoding/xml"
55
"fmt"
66
"io"
7+
"os"
78
"path/filepath"
89
"sort"
910
"strings"
@@ -52,6 +53,11 @@ func (sch *Schema) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
5253
}
5354

5455
func (sch *Schema) compile() {
56+
if sch.TargetNamespace == "" {
57+
fmt.Fprintf(os.Stderr, "Warning: missing explicit /xsd:chema/@targetNamespace; using '%s' instead\n", sch.GoPackageName())
58+
sch.TargetNamespace = sch.GoPackageName()
59+
}
60+
5561
for idx := range sch.Elements {
5662
el := &sch.Elements[idx]
5763
el.compile(sch, nil)

tests/xsd-examples/valid/issue129.xsd.out

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Code generated by https://github.com/gocomply/xsd2go; DO NOT EDIT.
2-
// Models for
2+
// Models for issue129
33
package issue129
44

55
import (
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
3+
<!-- definition of simple elements -->
4+
<xs:element name="name" type="xs:string"/>
5+
<!-- definition of complex elements -->
6+
<xs:element name="referencingthename">
7+
<xs:complexType>
8+
<xs:sequence>
9+
<xs:element ref="name"/>
10+
</xs:sequence>
11+
</xs:complexType>
12+
</xs:element>
13+
</xs:schema>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Code generated by https://github.com/gocomply/xsd2go; DO NOT EDIT.
2+
// Models for without_targetNamespace
3+
package without_targetNamespace
4+
5+
import (
6+
"encoding/xml"
7+
)
8+
9+
// Element
10+
type Name struct {
11+
XMLName xml.Name `xml:"name"`
12+
13+
Text string `xml:",chardata"`
14+
}
15+
16+
// Element
17+
type Referencingthename struct {
18+
XMLName xml.Name `xml:"referencingthename"`
19+
20+
Name string `xml:",any"`
21+
}
22+
23+
// XSD ComplexType declarations
24+
25+
// XSD SimpleType declarations

0 commit comments

Comments
 (0)