Golang encoding/xml: Difference between revisions

From wikinotes
Line 41: Line 41:
}
}
</syntaxhighlight>
</syntaxhighlight>
Known issues:
* xml namespaces don't work as expected: https://github.com/golang/go/issues/11496
* It doesn't appear that go's internal xml library supports schema validation
</blockquote><!-- Struct Tags -->
</blockquote><!-- Struct Tags -->

Revision as of 23:11, 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>
}

Known issues: