Skip to content

avbru/xml

Repository files navigation

This package is basically golang encoding/xml fork with fixes to support:

  • omitempty tag for struct fields
  • omitempty tag for nested xml tags
package main

import (
	"encoding/xml"	
	 oxml "github.com/avbru/xml"
)

type Test struct {
	Nested struct {
		Something string
	} `xml:"nested,omitempty"`
	NestedWithPath string `xml:"nestedL1>nestedL2>nestedwithpath,omitempty"`
}

func main() {
	d, err := xml.Marshal(&Test{})
	if err != nil {
		panic(err)
	}
	println("standart xml: ", string(d))
	
	
	d, err = oxml.Marshal(&Test{})
	if err != nil {
		panic(err)
	}
	println("oxml: ", string(d))
	
	
}

Example:

https://play.golang.org/p/wGPvdvlObFA

About

omitempty support for struct fields

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages