Golang encoding/xml: Difference between revisions
From wikinotes
No edit summary |
No edit summary |
||
Line 29: | Line 29: | ||
* <code>xml.Unmarshall(your_type)</code> will use type info to serialize/deserialize objects | * <code>xml.Unmarshall(your_type)</code> will use type info to serialize/deserialize objects | ||
</blockquote><!-- Basics --> | </blockquote><!-- Basics --> | ||
= Struct Tags = | |||
<blockquote> | |||
See full details [https://pkg.go.dev/encoding/xml@go1.18.3#Marshal here] | |||
<syntaxhighlight lang="bash"> | |||
type User struct { | |||
Name `xml:"Name"` // <User><Name>value</Name></User> | |||
Color `xml:"color,attr"` // <User color="value"></User> | |||
Skip `xml:"-"` // <User></User> | |||
} | |||
</syntaxhighlight> | |||
</blockquote><!-- Struct Tags --> |
Revision as of 23:03, 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> }