xml

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2023 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package xml has some utilities for XML codec

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func StructToXML

func StructToXML(interFace interface{}) (xmlData string, err error)

StructToXML convert struct to XML The struct must have xml tags

:param interFace: The struct data with xml tags

Example

var a NTP

thing, err := xml.StructToXML(a)

fmt.Println(thing)

func XMLToStruct

func XMLToStruct(interFace interface{}, xmlData string) error

XMLToStruct convert XML to a Struct The struct must have xml tags

:param interFace: A pointer to a variable of the struct data with xml tags
:param xmlData: The XML data

Example

type NTP struct {
	NTPServersData struct {
		SourceInterface string `yaml:"source_interface" json:"source_interface" xml:"source_interface"`
		NTPServerKey    []struct {
			IPv4Host string `yaml:"ipv4_host" json:"ipv4_host" xml:"ipv4_host"`
			Priority bool   `yaml:"priority" json:"priority" xml:"priority"`
		} `yaml:"ntp_servers" json:"ntp_servers" xml:"ntp_servers"`
	} `yaml:"ntp" json:"ntp" xml:"ntp"`
}

var a NTP

err := json.XMLToStruct(&a, ntpXml)
if err != nil {
	log.Fatal(err)
}

fmt.Println(a)

Types

This section is empty.

Jump to

Keyboard shortcuts

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