Open akbaruddink opened 4 years ago
Having the same issue with a XSD file that has <xs:schema xmlns:xs = "http://www.w3.org/2001/XMLSchema">
and only xs namespace.
@mr-kashif, could you please provide all the XSD files for me to reproduce?
@isimluk This specification from gaeb (a german standard for b2b communication) triggers the same error. GAEB_DA_XML_Lib_3.3_2021-05.xsd.txt (renamed to .txt because github does not allow .xsd)
Processing 'GAEB_DA_XML_Lib_3.3_2021-05.xsd'
Parsing: GAEB_DA_XML_Lib_3.3_2021-05.xsd
panic: Internal error: Unknown xmlns prefix:
goroutine 1 [running]:
github.com/gocomply/xsd2go/pkg/xsd.(*Schema).xmlnsByPrefix(...)
C:/Users/xf/Desktop/tmp/gaeb/xsd2go/pkg/xsd/schema.go:111
github.com/gocomply/xsd2go/pkg/xsd.(*Schema).findReferencedSchemaByPrefix(0xc000185560?, {0x0, 0x0})
C:/Users/xf/Desktop/tmp/gaeb/xsd2go/pkg/xsd/schema.go:105 +0x79
github.com/gocomply/xsd2go/pkg/xsd.(*Schema).findReferencedType(0xc0001bab40, {0xc000185560, 0xa})
C:/Users/xf/Desktop/tmp/gaeb/xsd2go/pkg/xsd/schema.go:90 +0x8e
github.com/gocomply/xsd2go/pkg/xsd.(*Element).compile(0xc000350000, 0xc000034000?, 0x300000002?)
C:/Users/xf/Desktop/tmp/gaeb/xsd2go/pkg/xsd/element.go:145 +0x1a6
github.com/gocomply/xsd2go/pkg/xsd.(*Sequence).compile(0xc000302850, 0x791be0?, 0x0?)
C:/Users/xf/Desktop/tmp/gaeb/xsd2go/pkg/xsd/sequence.go:21 +0x5d
github.com/gocomply/xsd2go/pkg/xsd.(*ComplexType).compile(0xc00046a000, 0xc0001bab40, 0xc000012180?)
C:/Users/xf/Desktop/tmp/gaeb/xsd2go/pkg/xsd/types.go:106 +0x6d
github.com/gocomply/xsd2go/pkg/xsd.(*Schema).compile(0xc0001bab40)
C:/Users/xf/Desktop/tmp/gaeb/xsd2go/pkg/xsd/schema.go:61 +0x10a
github.com/gocomply/xsd2go/pkg/xsd.(*Workspace).loadXsd(0xc0001b0460, {0xc000012180, 0x1f}, 0x1)
C:/Users/xf/Desktop/tmp/gaeb/xsd2go/pkg/xsd/workspace.go:95 +0xdfa
github.com/gocomply/xsd2go/pkg/xsd.NewWorkspace({0xc000185294, 0x9}, {0xc000012180, 0x1f}, {0x7e6638, 0x0, 0x0})
C:/Users/xf/Desktop/tmp/gaeb/xsd2go/pkg/xsd/workspace.go:27 +0xfc
github.com/gocomply/xsd2go/pkg/xsd2go.Convert({0xc000012180, 0x1f}, {0xc00000a0f0, 0x4}, {0xc00000a100, 0x4}, {0x7e6638, 0x0, 0x0})
C:/Users/xf/Desktop/tmp/gaeb/xsd2go/pkg/xsd2go/generate.go:12 +0x15a
github.com/gocomply/xsd2go/cli/cmd.glob..func2(0xc0001c82c0?)
C:/Users/xf/Desktop/tmp/gaeb/xsd2go/cli/cmd/cmd.go:44 +0xd1
github.com/urfave/cli.HandleAction({0x505260?, 0x575d50?}, 0x7?)
C:/Users/xf/Desktop/tmp/gaeb/xsd2go/vendor/github.com/urfave/cli/app.go:524 +0xa8
github.com/urfave/cli.Command.Run({{0x559143, 0x7}, {0x0, 0x0}, {0x0, 0x0, 0x0}, {0x56d98c, 0x44}, {0x0, ...}, ...}, ...)
C:/Users/xf/Desktop/tmp/gaeb/xsd2go/vendor/github.com/urfave/cli/command.go:173 +0x652
github.com/urfave/cli.(*App).Run(0xc0001bc380, {0xc000102000, 0x5, 0x8})
C:/Users/xf/Desktop/tmp/gaeb/xsd2go/vendor/github.com/urfave/cli/app.go:277 +0x8a7
github.com/gocomply/xsd2go/cli/cmd.Execute()
C:/Users/xf/Desktop/tmp/gaeb/xsd2go/cli/cmd/cmd.go:21 +0x128
main.main()
C:/Users/xf/Desktop/tmp/gaeb/xsd2go/cli/gocomply_xsd2go/main.go:8 +0x19
@isimluk , I had the same problem and managed to create a minimal example:
<?xml version="1.0" encoding="UTF-8" ?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<!-- definition of simple elements -->
<xs:element name="name" type="xs:string"/>
<!-- definition of complex elements -->
<xs:element name="referencingthename">
<xs:complexType>
<xs:sequence>
<xs:element ref="name"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
Could you have a look at it?
Yes please to the above comment.
The problem occurs when the parser searches a referenced element without a prefix like ref="name"
and then does not find a namespace for it. To resolve it, you can specify a targetNamespace
for your schema like this:
<?xml version="1.0" encoding="UTF-8" ?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="exampleNamespace">
<!-- definition of simple elements -->
<xs:element name="name" type="xs:string"/>
<!-- definition of complex elements -->
<xs:element name="referencingthename">
<xs:complexType>
<xs:sequence>
<xs:element ref="name"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
Not able to generate structs from xsd.
patent-document.xsd