forked from gwatts/pinfinder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
plist.go
56 lines (48 loc) · 928 Bytes
/
plist.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
package main
import (
"encoding/xml"
"io"
"os"
)
type plistval struct {
Type string
Value string
}
// simple helper to load plist dicts
type plistDict map[string]plistval
func (p *plistDict) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
*p = make(plistDict)
var sval struct {
XMLName xml.Name
Value string `xml:",chardata"`
}
var key string
for {
t, err := d.Token()
if err != nil {
if err == io.EOF {
return nil
}
return err
}
switch t1 := t.(type) {
case xml.StartElement:
if err := d.DecodeElement(&sval, &t1); err != nil {
return err
}
if sval.XMLName.Local == "key" {
key = sval.Value
} else {
(*p)[key] = plistval{Type: sval.XMLName.Local, Value: sval.Value}
}
}
}
}
func loadXML(path string, v interface{}) error {
f, err := os.Open(path)
if err != nil {
return err
}
defer f.Close()
return xml.NewDecoder(f).Decode(v)
}