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 ¶
This section is empty.
Variables ¶
var ( DefaultRootTag = "doc" UseGoEmptyElementSyntax = false // if 'true' encode empty element as "<tag></tag>" instead of "<tag/> )
Functions ¶
func XMLEscapeChars ¶
func XMLEscapeChars(b bool)
XMLEscapeChars(true) forces escaping invalid characters in attribute and element values. NOTE: this is brute force with NO interrogation of '&' being escaped already; if it is then '&' will be re-escaped as '&amp;'.
The values are: " " ' ' < < > > & &
Types ¶
This section is empty.