/
hlsortdeclaration.go
51 lines (44 loc) · 1.33 KB
/
hlsortdeclaration.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
package pnml
import (
"encoding/xml"
"errors"
"fmt"
)
type HLSortDeclaration struct {
XMLName xml.Name `xml:"namedsort"`
ID *string `xml:"id,attr"`
Name *string `xml:"name,attr"`
Sort *HLSort `xml:",any"`
}
func (h *HLSortDeclaration) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
type hlsortdeclaration HLSortDeclaration
var hh hlsortdeclaration
if err := d.DecodeElement(&hh, &start); err != nil {
return err
}
line, col := d.InputPos()
if hh.ID == nil || *hh.ID == "" {
msg := fmt.Sprint(modelPath, " at line ", line, ", col ", col, ", namedsort without id attribute (or with empty id)")
return errors.New(msg)
}
if hh.Name == nil || *hh.Name == "" {
msg := fmt.Sprint(modelPath, " at line ", line, ", col ", col, ", namedsort without name attribute (or with empty name)")
return errors.New(msg)
}
if hh.Sort == nil {
msg := fmt.Sprint(modelPath, " at line ", line, ", col ", col, ", namedsort without sort")
return errors.New(msg)
}
*h = HLSortDeclaration(hh)
return nil
}
func (h HLSortDeclaration) MarshalXML(e *xml.Encoder, start xml.StartElement) error {
type tmpH struct {
XMLName xml.Name `xml:"namedsort"`
ID *string `xml:"id,attr"`
Name *string `xml:"name,attr"`
Sort interface{}
}
t := tmpH{h.XMLName, h.ID, h.Name, h.Sort.Value}
return e.Encode(t)
}