-
Notifications
You must be signed in to change notification settings - Fork 0
/
xml.go
33 lines (28 loc) · 787 Bytes
/
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
package senml
import (
"encoding/xml"
)
const (
xmlStart = `<sensml xmlns="urn:ietf:params:xml:ns:senml">`
xmlEnd = `</sensml>`
xmlNamespace = `urn:ietf:params:xml:ns:senml`
)
type xmlContainer struct {
XMLName xml.Name `xml:"sensml" name:"urn:ietf:params:xml:ns:senml"`
XMLNamespace string `xml:"xmlns,attr"`
Objs []Record
}
// EncodeXML encodes a list of measurements into XML.
func EncodeXML(list []Measurement) (b []byte, err error) {
c := xmlContainer{Objs: Encode(list), XMLNamespace: xmlNamespace}
return xml.Marshal(c)
}
// DecodeXML decodes a list of measurements from XML.
func DecodeXML(x []byte) ([]Measurement, error) {
c := new(xmlContainer)
err := xml.Unmarshal(x, c)
if err != nil {
return nil, err
}
return Decode(c.Objs)
}