xmltypes

package
v0.1.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 4, 2023 License: AGPL-3.0 Imports: 1 Imported by: 0

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) Get

func (b BoolAsInt) Get() int

Get returns this boolean as an integer

func (BoolAsInt) MarshalXML

func (b BoolAsInt) MarshalXML(e *xml.Encoder, start xml.StartElement) error

func (*BoolAsInt) Set

func (b *BoolAsInt) Set(v int)
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

func (b *BoolAsInt) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL