I have a struct that looks like this
// ReportsImport original data source for the report list. only SysrptID, Name, FileName are used.
// This is a mess, but breaking it up seems to affect the unmarshall
type ReportsImport struct {
XMLName xml.Name `xml:"ReportsImport"`
//Text string `xml:",chardata"`
//Xsi string `xml:"xsi,attr"`
//Xsd string `xml:"xsd,attr"`
Reports struct {
// Text string `xml:",chardata"`
ReportImport []struct {
Text string `xml:",chardata"`
SysrptID string `xml:"sysrptID"`
SQLVersion string `xml:"sqlVersion"`
FileName string `xml:"FileName"`
Name string `xml:"Name"`
ReportImport []struct {
Text string `xml:",chardata"`
SysrptID string `xml:"sysrptID"`
SQLVersion string `xml:"sqlVersion"`
FileName string `xml:"FileName"`
Name string `xml:"Name"`
ReportImport []struct {
Text string `xml:",chardata"`
SysrptID string `xml:"sysrptID"`
SQLVersion string `xml:"sqlVersion"`
FileName string `xml:"FileName"`
Name string `xml:"Name"`
} `xml:"ReportImport"`
} `xml:"ReportImport"`
} `xml:"ReportImport"`
} `xml:"Reports"`
//Path string `xml:"Path"`
}
to parse an xml file like this
<?xml version="1.0" encoding="utf-8"?>
<ReportsImport xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Reports>
<ReportImport>
<sysrptID>1</sysrptID>
<sqlVersion>8</sqlVersion>
<FileName>MDR\Account Statistics.RPT</FileName>
<Name>MDR - Account Statistics</Name>
</ReportImport>
<ReportImport>
<sysrptID>2</sysrptID>
<sqlVersion>8</sqlVersion>
<FileName>CTE\Call Progress.RPT</FileName>
<Name>CTE - Call Progress</Name>
</ReportImport>
<ReportImport>
<sysrptID>295</sysrptID>
<sqlVersion>9</sqlVersion>
<FileName>IS\Genesis Account Statistics minutes.rpt</FileName>
<Name>Genesis - Account Statistics Minutes</Name>
</ReportImport>
</Reports>
<Path>E:\Reports\Version20\</Path>
</ReportsImport>
and it works, but I want to clean up the struct and break it apart into a list and single items similar to this
type Import struct {
XMLName xml.Name `xml:"ReportsImport"`
Reports []ReportImport `xml:"Reports"`
}
type ReportImport struct {
XMLName xml.Name `xml:"ReportImport"`
Text string `xml:",chardata"`
SysrptID string `xml:"sysrptID"`
SQLVersion string `xml:"sqlVersion"`
FileName string `xml:"FileName"`
Name string `xml:"Name"`
}
But when I do this the collection is nil or of zero length, not sure what I missed.
The xml is kind of weird but its an old project [that it was produced for] and out of my control