I have an XML document. Some fields have their own format. Example:
<document>
<title>hello world</title>
<lines>
line 1
line 2
line 3
</lines>
</document>
I want to import it into a structure, for example:
type Document struct {
Title string `xml:"title"`
Lines []string `xml:"lines"`
}
Is there a way to implement a custom decoder that splits a string of strings into an array of strings ( ["line 1", "line 2", "line 3"])?
It can be made Lines a string type field and split after xml import, but this does not seem to be a very elegant solution. Is there a way to define a custom decoder for line splitting and combine it with an xml decoder?
source
share