-
Notifications
You must be signed in to change notification settings - Fork 5
/
property.go
41 lines (34 loc) · 999 Bytes
/
property.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
package tmx
import "encoding/xml"
// Property is any custom data added to elements of the map
type Property struct {
// Name is the name of the property
Name string `xml:"name,attr"`
// Type is the type of the property. It can be string, int, float, bool,
// color or file
Type string `xml:"type,attr"`
// Value is the value of the property
Value string `xml:"value,attr"`
}
func (p *Property) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
prop := struct {
// Name is the name of the property
Name string `xml:"name,attr"`
// Type is the type of the property. It can be string, int, float, bool,
// color or file
Type string `xml:"type,attr"`
// Value is the value of the property
Value string `xml:"value,attr"`
CharData string `xml:",chardata"`
}{}
if err := d.DecodeElement(&prop, &start); err != nil {
return err
}
p.Name = prop.Name
p.Type = prop.Type
p.Value = prop.Value
if len(p.Value) == 0 {
p.Value = prop.CharData
}
return nil
}