Golang encoding/xml: Difference between revisions
From wikinotes
No edit summary |
|||
Line 34: | Line 34: | ||
See full details [https://pkg.go.dev/encoding/xml@go1.18.3#Marshal here] | See full details [https://pkg.go.dev/encoding/xml@go1.18.3#Marshal here] | ||
<syntaxhighlight lang=" | <syntaxhighlight lang="go"> | ||
type User struct { | type User struct { | ||
Name `xml:"Name"` // <User><Name>value</Name></User> | Name `xml:"Name"` // <User><Name>value</Name></User> |
Revision as of 23:04, 25 June 2022
go's builtin library for parsing xml.
WARNING:
wip
Documentation
Tutorials
tutorialedge https://tutorialedge.net/golang/parsing-xml-with-golang/
Basics
To parse xml within go:
- you define
MarshallText/UnmarshallText
methods on an object- declare a variable with the types you'd like to use
xml.Unmarshall(your_type)
will use type info to serialize/deserialize objects
Struct Tags
See full details here
type User struct { Name `xml:"Name"` // <User><Name>value</Name></User> Color `xml:"color,attr"` // <User color="value"></User> Skip `xml:"-"` // <User></User> }