2017-08-29 15:06:08 -05:00

70 lines
2.3 KiB
Go

// Copyright 2017 Baliance. All rights reserved.
//
// Use of this source code is governed by the terms of the Affero GNU General
// Public License version 3.0 as published by the Free Software Foundation and
// appearing in the file LICENSE included in the packaging of this file. A
// commercial license can be purchased by contacting sales@baliance.com.
package chart
import (
"encoding/xml"
"fmt"
)
type Chart struct {
CT_RelId
}
func NewChart() *Chart {
ret := &Chart{}
ret.CT_RelId = *NewCT_RelId()
return ret
}
func (m *Chart) MarshalXML(e *xml.Encoder, start xml.StartElement) error {
if m == nil {
return nil
}
start.Attr = append(start.Attr, xml.Attr{Name: xml.Name{Local: "xmlns"}, Value: "http://schemas.openxmlformats.org/drawingml/2006/chart"})
start.Attr = append(start.Attr, xml.Attr{Name: xml.Name{Local: "xmlns:a"}, Value: "http://schemas.openxmlformats.org/drawingml/2006/main"})
start.Attr = append(start.Attr, xml.Attr{Name: xml.Name{Local: "xmlns:c"}, Value: "http://schemas.openxmlformats.org/drawingml/2006/chart"})
start.Attr = append(start.Attr, xml.Attr{Name: xml.Name{Local: "xmlns:r"}, Value: "http://schemas.openxmlformats.org/officeDocument/2006/relationships"})
start.Attr = append(start.Attr, xml.Attr{Name: xml.Name{Local: "xmlns:sh"}, Value: "http://schemas.openxmlformats.org/officeDocument/2006/sharedTypes"})
start.Attr = append(start.Attr, xml.Attr{Name: xml.Name{Local: "xmlns:xml"}, Value: "http://www.w3.org/XML/1998/namespace"})
start.Name.Local = "chart"
return m.CT_RelId.MarshalXML(e, start)
}
func (m *Chart) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
// initialize to default
m.CT_RelId = *NewCT_RelId()
for _, attr := range start.Attr {
if attr.Name.Local == "id" {
parsed, err := attr.Value, error(nil)
if err != nil {
return err
}
m.IdAttr = parsed
}
}
// skip any extensions we may find, but don't support
for {
tok, err := d.Token()
if err != nil {
return fmt.Errorf("parsing Chart: %s", err)
}
if el, ok := tok.(xml.EndElement); ok && el.Name == start.Name {
break
}
}
return nil
}
func (m *Chart) Validate() error {
return m.ValidateWithPath("Chart")
}
func (m *Chart) ValidateWithPath(path string) error {
if err := m.CT_RelId.ValidateWithPath(path); err != nil {
return err
}
return nil
}