-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathxml.go
57 lines (48 loc) · 1.25 KB
/
xml.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
package symbol
import (
_ "embed"
"encoding/xml"
"fmt"
"strings"
)
//go:embed EU0AF01C.xml
var EU0AF01C_xml []byte
//go:embed EU0AF01O.xml
var EU0AF01O_xml []byte
type XMLSymbol struct {
Text string `xml:",chardata"`
SYMBOLNAME string `xml:"SYMBOLNAME"`
SYMBOLNUMBER int `xml:"SYMBOLNUMBER"`
FLASHADDRESS string `xml:"FLASHADDRESS"`
DESCRIPTION string `xml:"DESCRIPTION"`
}
type DocumentElement struct {
XMLName xml.Name `xml:"DocumentElement"`
Text string `xml:",chardata"`
Symbols []XMLSymbol `xml:",any"`
}
var xmlMap map[string][]byte = map[string][]byte{
"EU0AF01C": EU0AF01C_xml,
"EU0BF01C": EU0AF01C_xml,
"EU0CF01C": EU0AF01C_xml,
"EU0AF01O": EU0AF01O_xml,
"EU0BF01O": EU0AF01O_xml,
"EU0CF01O": EU0AF01O_xml,
"EU06Z44O": EU0AF01O_xml,
}
func xml2map(name string) (map[int]string, error) {
xmlBytes, ok := xmlMap[strings.ToUpper(name)]
if !ok {
return nil, fmt.Errorf("unknown xml: %s", name)
}
var symbols DocumentElement
if err := xml.Unmarshal(xmlBytes, &symbols); err != nil {
return nil, err
}
results := make(map[int]string)
for _, s := range symbols.Symbols {
//fmt.Fprintf(f, "%d %s %s\n", s.SYMBOLNUMBER, s.DESCRIPTION, s.SYMBOLNAME)
results[s.SYMBOLNUMBER] = s.DESCRIPTION
}
return results, nil
}