-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathxml.go
More file actions
34 lines (29 loc) · 679 Bytes
/
Copy pathxml.go
File metadata and controls
34 lines (29 loc) · 679 Bytes
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
package main
import (
"encoding/xml"
"io/ioutil"
"os"
)
type TrainLegs struct {
XMLName xml.Name `xml:"TrainLegs"`
//Trains map[string]train `xml:"TrainLeg"`
Trains []Train `xml:"TrainLeg"`
}
//func unmarshalTickets(byteValue []byte) (map[string]train, error) {
func unmarshalTickets(byteValue []byte) ([]Train, error) {
var tl TrainLegs
err := xml.Unmarshal(byteValue, &tl)
if err != nil {
return nil, err
}
return tl.Trains, nil
}
func parseXmlFile(filename string) ([]byte, error) {
xmlFile, err := os.Open(filename)
if err != nil {
return nil, err
}
defer xmlFile.Close()
// read our opened xmlFile as a byte array.
return ioutil.ReadAll(xmlFile)
}