Documentation ¶
Overview ¶
Package xmltypes contains several types that encode differently in XML. Each of the types in this package contain four functions.
- Get returns the encoded value. - Set sets using an encoded value. - MarshalXML and UnmarshalXML marshal to / from xml.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BoolAsInt ¶
type BoolAsInt bool
BoolAsInt is a boolean that is marshaled as an integer in xml. 0 represents false, any other number represents true.
Example (Marshal) ¶
{ b := BoolAsInt(false) bytes, _ := xml.Marshal(b) fmt.Println(string(bytes)) } { b := BoolAsInt(true) bytes, _ := xml.Marshal(b) fmt.Println(string(bytes)) }
Output: <BoolAsInt>0</BoolAsInt> <BoolAsInt>1</BoolAsInt>
func (BoolAsInt) MarshalXML ¶
func (*BoolAsInt) Set ¶
Example ¶
var b BoolAsInt b.Set(0) fmt.Println(b) fmt.Println(b.Get()) b.Set(1) fmt.Println(b) fmt.Println(b.Get())
Output: false 0 true 1
func (*BoolAsInt) UnmarshalXML ¶
type BoolAsString ¶
type BoolAsString bool
BoolAsInt is a boolean that is marshaled as a string in xml. "TRUE" represents true, any other string represents false.
Example (Marshal) ¶
{ b := BoolAsString(false) bytes, _ := xml.Marshal(b) fmt.Println(string(bytes)) } { b := BoolAsString(true) bytes, _ := xml.Marshal(b) fmt.Println(string(bytes)) }
Output: <BoolAsString>FALSE</BoolAsString> <BoolAsString>TRUE</BoolAsString>
func (BoolAsString) Get ¶
func (b BoolAsString) Get() string
func (BoolAsString) MarshalXML ¶
func (b BoolAsString) MarshalXML(e *xml.Encoder, start xml.StartElement) error
func (*BoolAsString) Set ¶
func (b *BoolAsString) Set(v string)
Example ¶
var b BoolAsString b.Set("FALSE") fmt.Println(b) fmt.Println(b.Get()) b.Set("TRUE") fmt.Println(b) fmt.Println(b.Get())
Output: false FALSE true TRUE
func (*BoolAsString) UnmarshalXML ¶
func (b *BoolAsString) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error
type StringWithZero ¶
type StringWithZero string
StringWithZero is like string, but marshals the empty string as "0".
Example (Marshal) ¶
{ s := StringWithZero("") bytes, _ := xml.Marshal(s) fmt.Println(string(bytes)) } { b := StringWithZero("hello world") bytes, _ := xml.Marshal(b) fmt.Println(string(bytes)) }
Output: <StringWithZero>0</StringWithZero> <StringWithZero>hello world</StringWithZero>
func (StringWithZero) Get ¶
func (s StringWithZero) Get() string
func (StringWithZero) MarshalXML ¶
func (s StringWithZero) MarshalXML(e *xml.Encoder, start xml.StartElement) error
func (*StringWithZero) Set ¶
func (s *StringWithZero) Set(v string)
Example ¶
var s StringWithZero s.Set("0") fmt.Println(s) fmt.Println(s.Get()) s.Set("hello world") fmt.Println(s) fmt.Println(s.Get())
Output: 0 hello world hello world
func (*StringWithZero) UnmarshalXML ¶
func (s *StringWithZero) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error
Click to show internal directories.
Click to hide internal directories.