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
- func Struct2MapWithDateFormat(dateFormat string, obj interface{}) map[string]interface{}
- func Xml(v interface{}, rootTag ...string) ([]byte, error)
- func XmlIndent(v interface{}, prefix, indent string, rootTag ...string) ([]byte, error)
- func XmlIndentWithDateFormat(dateFormat string, v interface{}, prefix, indent string, rootTag ...string) ([]byte, error)
- func XmlWithDateFormat(dateFormat string, v interface{}, rootTag ...string) ([]byte, error)
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 ¶
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.