Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion gentests/_testgen/testgen.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ func genXSDTests(cfg xsdgen.Config, data []byte, pkg string) (code, tests *ast.F
t.Fatal("expected one sample file, found ", samples)
}

input, err := ioutil.ReadFile(samples[0])
input, err := os.ReadFile(samples[0])
if err != nil {
t.Fatal(err)
}
Expand Down
4 changes: 2 additions & 2 deletions gentests/bindata/bindata_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions gentests/books/books_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 10 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
module github.com/nukib/go-xml

go 1.21
go 1.22.0

toolchain go1.22.5

require (
golang.org/x/net v0.19.0
golang.org/x/text v0.14.0
golang.org/x/tools v0.16.0
golang.org/x/net v0.32.0
golang.org/x/text v0.21.0
golang.org/x/tools v0.28.0
)

require golang.org/x/mod v0.14.0 // indirect
require (
golang.org/x/mod v0.22.0 // indirect
golang.org/x/sync v0.10.0 // indirect
)
20 changes: 12 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
golang.org/x/mod v0.14.0 h1:dGoOF9QVLYng8IHTm7BAyWqCqSheQ5pYWGhzW00YJr0=
golang.org/x/mod v0.14.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
golang.org/x/net v0.19.0 h1:zTwKpTd2XuCqf8huc7Fo2iSy+4RHPd10s4KzeTnVr1c=
golang.org/x/net v0.19.0/go.mod h1:CfAk/cbD4CthTvqiEl8NpboMuiuOYsAr/7NOjZJtv1U=
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
golang.org/x/tools v0.16.0 h1:GO788SKMRunPIBCXiQyo2AaexLstOrVhuAL5YwsckQM=
golang.org/x/tools v0.16.0/go.mod h1:kYVVN6I1mBNoB1OX+noeBjbRk4IUEPa7JJ+TJMEooJ0=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
golang.org/x/mod v0.22.0 h1:D4nJWe9zXqHOmWqj4VMOJhvzj7bEZg4wEYa759z1pH4=
golang.org/x/mod v0.22.0/go.mod h1:6SkKJ3Xj0I0BrPOZoBy3bdMptDDU9oJrpohJ3eWZ1fY=
golang.org/x/net v0.32.0 h1:ZqPmj8Kzc+Y6e0+skZsuACbx+wzMgo5MQsJh9Qd6aYI=
golang.org/x/net v0.32.0/go.mod h1:CwU0IoeOlnQQWJ6ioyFrfRuomB8GKF6KbYXZVyeXNfs=
golang.org/x/sync v0.10.0 h1:3NQrjDixjgGwUOCaF8w2+VYHv0Ve/vGYSbdkTa98gmQ=
golang.org/x/sync v0.10.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo=
golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ=
golang.org/x/tools v0.28.0 h1:WuB6qZ4RPCQo5aP3WdKZS7i595EdWqWR8vqJTlwTVK8=
golang.org/x/tools v0.28.0/go.mod h1:dcIOrVd3mfQKTgrDVQHqCPMWy6lnhfhtX3hLXYVLfRw=
1 change: 1 addition & 0 deletions wsdl/wsdl.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ type Definition struct {
Ports []Port
Message map[xml.Name]Message
TargetNS string
Types *xmltree.Element
}

func (def *Definition) String() string {
Expand Down
25 changes: 15 additions & 10 deletions wsdlgen/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,24 @@ func (cfg *Config) GenSource(files ...string) ([]byte, error) {
// command-line interfaces to the wsdlgen package.
func (cfg *Config) GenCLI(arguments ...string) error {
var (
err error
replaceRules commandline.ReplaceRuleList
ports commandline.Strings
fs = flag.NewFlagSet("wsdlgen", flag.ExitOnError)
packageName = fs.String("pkg", "", "name of the generated package")
comment = fs.String("c", "", "First line of package-level comments")
output = fs.String("o", "wsdlgen_output.go", "name of the output file")
verbose = fs.Bool("v", false, "print verbose output")
debug = fs.Bool("vv", false, "print debug output")
err error
replaceRules commandline.ReplaceRuleList
ports commandline.Strings
fs = flag.NewFlagSet("wsdlgen", flag.ExitOnError)
packageName = fs.String("pkg", "", "name of the generated package")
comment = fs.String("c", "", "First line of package-level comments")
followImports = fs.Bool("f", false, "follow xsd import statements; load imported references recursively into scope")
output = fs.String("o", "wsdlgen_output.go", "name of the output file")
verbose = fs.Bool("v", false, "print verbose output")
debug = fs.Bool("vv", false, "print debug output")
)
fs.Var(&replaceRules, "r", "replacement rule 'regex -> repl' (can be used multiple times)")
fs.Var(&ports, "port", "gen code for this port (can be used multiple times)")
if err = fs.Parse(arguments); err != nil {
return err
}
if fs.NArg() == 0 {
return errors.New("Usage: wsdlgen [-r rule] [-o file] [-port name] [-pkg pkg] file ...")
return errors.New("usage: wsdlgen [-r rule] [-o file] [-port name] [-pkg pkg] file ... ")
}

if *debug {
Expand All @@ -60,6 +61,10 @@ func (cfg *Config) GenCLI(arguments ...string) error {
if len(ports) > 0 {
cfg.Option(OnlyPorts(ports...))
}

cfg.XSDOption(xsdgen.FollowImports(*followImports))
cfg.xsdgen.FilesRead = make(map[string]bool)

for _, r := range replaceRules {
cfg.XSDOption(xsdgen.Replace(r.From.String(), r.To))
}
Expand Down
5 changes: 2 additions & 3 deletions wsdlgen/examples/chemspell/wsdlgen_output.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

110 changes: 55 additions & 55 deletions wsdlgen/examples/forecast/wsdlgen_output.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 6 additions & 8 deletions wsdlgen/wsdlgen.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"go/ast"
"golang.org/x/text/cases"
"golang.org/x/text/language"
"os"
)

var caser = cases.Title(language.English, cases.NoLower)
Expand Down Expand Up @@ -99,16 +98,15 @@ func (cfg *Config) GenAST(files ...string) (*ast.File, error) {
if cfg.pkgHeader == "" {
cfg.pkgHeader = fmt.Sprintf("Package %s", cfg.pkgName)
}

docs := make([][]byte, 0, len(files))
for _, filename := range files {
if data, err := os.ReadFile(filename); err != nil {
return nil, err
} else {
cfg.debugf("read %s", filename)
docs = append(docs, data)
}
data, err := cfg.xsdgen.ReadFiles(files...)
if err != nil {
return nil, err
}

docs = append(docs, data...)

cfg.debugf("parsing WSDL file %s", files[0])
def, err := wsdl.Parse(docs[0])
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion wsdlgen/wsdlgen_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func testGen(t *testing.T, files ...string) {
cfg.xsdgen.Option(xsdgen.DefaultOptions...)
cfg.xsdgen.Option(xsdgen.UseFieldNames())

args := []string{"-vv", "-o", outputFile.Name()}
args := []string{"-vv", "-f", "-o", outputFile.Name()}
err = cfg.GenCLI(append(args, files...)...)
if err != nil {
t.Error(err)
Expand Down
2 changes: 1 addition & 1 deletion xmltree/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ func ExampleMarshal() {
// </toc>
}

func ExampleMarshalNested() {
func ExampleMarshal_nested() {
input := []byte(`<?xml version="1.0" encoding="UTF-8"?>
<toc>
<level1>
Expand Down
10 changes: 5 additions & 5 deletions xmltree/xmltree.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func (scope *Scope) ResolveDefault(qname, defaultns string) xml.Name {
if defaultns == "" || strings.Contains(qname, ":") {
return scope.Resolve(qname)
}
return xml.Name{defaultns, qname}
return xml.Name{Space: defaultns, Local: qname}
}

// Prefix is the inverse of Resolve. It uses the closest prefix
Expand Down Expand Up @@ -166,9 +166,9 @@ func (scope *Scope) pushNS(tag xml.StartElement) []xml.Attr {
var newAttrs []xml.Attr
for _, attr := range tag.Attr {
if attr.Name.Space == "xmlns" {
ns = append(ns, xml.Name{attr.Value, attr.Name.Local})
ns = append(ns, xml.Name{Space: attr.Value, Local: attr.Name.Local})
} else if attr.Name.Local == "xmlns" {
ns = append(ns, xml.Name{attr.Value, ""})
ns = append(ns, xml.Name{Space: attr.Value})
} else {
newAttrs = append(newAttrs, attr)
}
Expand Down Expand Up @@ -269,7 +269,7 @@ walk:
el.Children = append(el.Children, child)
case xml.EndElement:
if tok.Name != el.Name {
return fmt.Errorf("Expecting </%s>, got </%s>", el.Prefix(el.Name), el.Prefix(tok.Name))
return fmt.Errorf("expecting </%s>, got </%s>", el.Prefix(el.Name), el.Prefix(tok.Name))
}
el.Content = data[int(begin):int(end)]
break walk
Expand Down Expand Up @@ -308,7 +308,7 @@ func (el *Element) SetAttr(space, local, value string) {
}
}
el.StartElement.Attr = append(el.StartElement.Attr, xml.Attr{
Name: xml.Name{space, local},
Name: xml.Name{Space: space, Local: local},
Value: value,
})
}
Expand Down
Loading