-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
EG_PContentBase.go
106 lines (98 loc) · 3 KB
/
EG_PContentBase.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
package wml
import (
"encoding/xml"
"fmt"
"go.devnw.com/ooxml"
)
type EG_PContentBase struct {
CustomXml *CT_CustomXmlRun
FldSimple []*CT_SimpleField
Hyperlink *CT_Hyperlink
}
func NewEG_PContentBase() *EG_PContentBase {
ret := &EG_PContentBase{}
return ret
}
func (m *EG_PContentBase) MarshalXML(e *xml.Encoder, start xml.StartElement) error {
if m.CustomXml != nil {
secustomXml := xml.StartElement{Name: xml.Name{Local: "w:customXml"}}
e.EncodeElement(m.CustomXml, secustomXml)
}
if m.FldSimple != nil {
sefldSimple := xml.StartElement{Name: xml.Name{Local: "w:fldSimple"}}
for _, c := range m.FldSimple {
e.EncodeElement(c, sefldSimple)
}
}
if m.Hyperlink != nil {
sehyperlink := xml.StartElement{Name: xml.Name{Local: "w:hyperlink"}}
e.EncodeElement(m.Hyperlink, sehyperlink)
}
return nil
}
func (m *EG_PContentBase) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
// initialize to default
lEG_PContentBase:
for {
tok, err := d.Token()
if err != nil {
return err
}
switch el := tok.(type) {
case xml.StartElement:
switch el.Name {
case xml.Name{Space: "http://schemas.openxmlformats.org/wordprocessingml/2006/main", Local: "customXml"},
xml.Name{Space: "http://purl.oclc.org/ooxml/wordprocessingml/main", Local: "customXml"}:
m.CustomXml = NewCT_CustomXmlRun()
if err := d.DecodeElement(m.CustomXml, &el); err != nil {
return err
}
case xml.Name{Space: "http://schemas.openxmlformats.org/wordprocessingml/2006/main", Local: "fldSimple"},
xml.Name{Space: "http://purl.oclc.org/ooxml/wordprocessingml/main", Local: "fldSimple"}:
tmp := NewCT_SimpleField()
if err := d.DecodeElement(tmp, &el); err != nil {
return err
}
m.FldSimple = append(m.FldSimple, tmp)
case xml.Name{Space: "http://schemas.openxmlformats.org/wordprocessingml/2006/main", Local: "hyperlink"},
xml.Name{Space: "http://purl.oclc.org/ooxml/wordprocessingml/main", Local: "hyperlink"}:
m.Hyperlink = NewCT_Hyperlink()
if err := d.DecodeElement(m.Hyperlink, &el); err != nil {
return err
}
default:
office.Log("skipping unsupported element on EG_PContentBase %v", el.Name)
if err := d.Skip(); err != nil {
return err
}
}
case xml.EndElement:
break lEG_PContentBase
case xml.CharData:
}
}
return nil
}
// Validate validates the EG_PContentBase and its children
func (m *EG_PContentBase) Validate() error {
return m.ValidateWithPath("EG_PContentBase")
}
// ValidateWithPath validates the EG_PContentBase and its children, prefixing error messages with path
func (m *EG_PContentBase) ValidateWithPath(path string) error {
if m.CustomXml != nil {
if err := m.CustomXml.ValidateWithPath(path + "/CustomXml"); err != nil {
return err
}
}
for i, v := range m.FldSimple {
if err := v.ValidateWithPath(fmt.Sprintf("%s/FldSimple[%d]", path, i)); err != nil {
return err
}
}
if m.Hyperlink != nil {
if err := m.Hyperlink.ValidateWithPath(path + "/Hyperlink"); err != nil {
return err
}
}
return nil
}