xml

package
v0.0.0-...-dc333dc Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Examples

Constants

View Source
const Format = "xml"

Variables

This section is empty.

Functions

This section is empty.

Types

type Marshaller

type Marshaller struct {
}

func (Marshaller) Marshal

func (Marshaller) Marshal(in interface{}, variable model.ContentVariable) (out string, err error)
Example
value := map[string]interface{}{"-attr": "attrVal", "body": "bodyVal"}
marshaller, ok := base.Get(Format)
if !ok {
	return
}

fmt.Println(marshaller.Marshal(value, model.ContentVariable{
	Name: "example",
	Type: model.Structure,
	SubContentVariables: []model.ContentVariable{
		{Name: "-attr"},
		{Name: "body"},
	},
}))
Output:
<example attr="attrVal"><body>bodyVal</body></example> <nil>
Example (PrimitiveBool)
value := true
marshaller, ok := base.Get(Format)
if !ok {
	return
}

fmt.Println(marshaller.Marshal(value, model.ContentVariable{
	Name: "b",
}))
Output:
<b>true</b> <nil>
Example (PrimitiveFloat)
value := 2.4
marshaller, ok := base.Get(Format)
if !ok {
	return
}

fmt.Println(marshaller.Marshal(value, model.ContentVariable{
	Name: "f",
}))
Output:
<f>2.4</f> <nil>
Example (PrimitiveInt)
value := 24
marshaller, ok := base.Get(Format)
if !ok {
	return
}

fmt.Println(marshaller.Marshal(value, model.ContentVariable{
	Name: "int",
}))
Output:
<int>24</int> <nil>
Example (PrimitiveString)
value := "foo"
marshaller, ok := base.Get(Format)
if !ok {
	return
}

fmt.Println(marshaller.Marshal(value, model.ContentVariable{
	Name: "str",
}))
Output:
<str>foo</str> <nil>
Example (SerializationOptionXmlAttribute)
value := map[string]interface{}{"attr": "attrVal", "body": "bodyVal"}
marshaller, ok := base.Get(Format)
if !ok {
	return
}

fmt.Println(marshaller.Marshal(value, model.ContentVariable{
	Name: "example",
	Type: model.Structure,
	SubContentVariables: []model.ContentVariable{
		{Name: "attr", SerializationOptions: []string{models.SerializationOptionXmlAttribute}},
		{Name: "body"},
	},
}))
Output:
<example attr="attrVal"><body>bodyVal</body></example> <nil>

func (Marshaller) Unmarshal

func (Marshaller) Unmarshal(in string, variable model.ContentVariable) (out interface{}, err error)

Jump to

Keyboard shortcuts

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