anyxml

package module
v0.0.0-...-54457d8 Latest Latest
Warning

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

Go to latest
Published: May 30, 2016 License: MIT Imports: 6 Imported by: 37

Documentation

Overview

anyxml - marshal an XML document from almost any Go variable Marshal XML from map[string]interface{}, arrays, slices, alpha/numeric, etc.

Wraps xml.Marshal with functionality in github.com/clbanning/mxj to create a more genericized XML marshaling capability. Note: unmarshaling the resultant XML may not return the original value, since tag labels may have been injected to create the XML representation of the value.

See mxj package documentation for more information. See anyxml_test.go for examples or just try Xml() or XmlIndent().

 Encode an arbitrary JSON object.
	package main

	import (
		"encoding/json"
		"fmt"
		"github.com/clbanning/anyxml"
	)

	func main() {
		jsondata := []byte(`[
			{ "somekey":"somevalue" },
			"string",
			3.14159265,
			true
		]`)
		var i interface{}
		err := json.Unmarshal(jsondata, &i)
		if err != nil {
			// do something
		}
		x, err := anyxml.XmlIndent(i, "", "  ", "mydoc")
		if err != nil {
			// do something else
		}
		fmt.Println(string(x))
	}

	output:
		<mydoc>
		  <somekey>somevalue</somekey>
		  <element>string</element>
		  <element>3.14159265</element>
		  <element>true</element>
		</mydoc>

Index

Constants

View Source
const (
	DefaultRootTag          = "doc"
	UseGoEmptyElementSyntax = false // if 'true' encode empty element as "<tag></tag>" instead of "<tag/>
)

Variables

This section is empty.

Functions

func Struct2MapWithDateFormat

func Struct2MapWithDateFormat(dateFormat string, obj interface{}) map[string]interface{}

func Xml

func Xml(v interface{}, rootTag ...string) ([]byte, error)

Encode arbitrary value as XML. Note: there are no guarantees.

func XmlIndent

func XmlIndent(v interface{}, prefix, indent string, rootTag ...string) ([]byte, error)

Encode an arbitrary value as a pretty XML string. Note: there are no guarantees.

func XmlIndentWithDateFormat

func XmlIndentWithDateFormat(dateFormat string, v interface{}, prefix, indent string, rootTag ...string) ([]byte, error)

Encode an arbitrary value as a pretty XML string. Note: there are no guarantees.

func XmlWithDateFormat

func XmlWithDateFormat(dateFormat string, v interface{}, rootTag ...string) ([]byte, error)

Encode arbitrary value as XML. Note: there are no guarantees.

Types

This section is empty.

Jump to

Keyboard shortcuts

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