I'm reading an xml file and automatically unmarshalling it.
I defined the data structure as follows:
type oDoc struct {
Body oBody `xml:"body"`
AutoStyle oAutoStyle `xml:"automatic-styles"`
}
type oBody struct {
Spreadsheet oSpread `xml:"spreadsheet"`
}
type oSpread struct {
Tables []oTable `xml:"table"`
}
type oTable struct {
Name string `xml:"name,attr"`
Rows []oRow `xml:"table-row"`
}
type oRow struct {
Cells []oCell `xml:"table-cell"`
Style string `xml:"style-name,attr"`
}
There is more further down but it doesn't matter for this example.
From an oRow object, I need to access the root oDoc object.
Is this possible? I've seen several examples using interfaces but this seems to require me manually adding each element to set the respective parent. I'm not sure I can do this as the unmarshalling is automatic.
Edit: Example of what I'm trying to achieve. oDoc splits into oTables and oStyles (styles not added for brevity). Each oRow has a style Name corresponding to an oStyle object. I want to be able to create a method that can do
rowOject.getStyleObject()
As per gonutz's suggestion, I could do something like
docObj.getRow(specificRow).getStyle(docObj)
and use that docObj to drilldown to the style I want but this like it is bad form. If it's the only/best solution, I'll go for it but seems like there should be a better way.
Any suggestions?