Go's xml
package is excellent and makes dealing with XML very easy. There's one thing I'm not sure how to do: when creating an XML document from a native struct, how do you specify the doctype?
For example, these structs:
type Person struct {
XMLName xml.Name `xml:"person"`
FirstName string `xml:"firstName"`
MiddleName string `xml:"middleName"`
LastName string `xml:"lastName"`
Age int64 `xml:"age"`
Skills []Skill `xml:"skills"`
}
type Skill struct {
XMLName xml.Name `xml:"skill"`
Name string `xml:"skillName"`
YearsPracticed int64 `xml:"practice"`
}
Will generate something like this XML:
<person>
<firstName>Bob</firstName>
<middleName></middleName>
<lastName>Jones</middleName>
<age>23</age>
<skills>
<skill>
<skillName>Cooking</skillName>
<practice>3</practice>
</skill>
<skill>
<skillName>Basketball</skillName>
<practice>4</practice>
</skill>
</skills>
</person>
Which is great, but what do I do to get this:
<?xml version="1.0" encoding="UTF-8"?>
<person>
<firstName>Bob</firstName>
<middleName></middleName>
...
It almost seems too simple, but is this a matter of doing a string append?
And, on the reverse, how would Go's XML parser handle a doctype in a block of text that you wanted to unmarshal into a set of structs? Ignore it?