Minor change
This commit is contained in:
parent
e5889250bd
commit
e06a834fdf
1 changed files with 51 additions and 0 deletions
|
|
@ -0,0 +1,51 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"encoding/xml"
|
||||
"fmt"
|
||||
"os"
|
||||
)
|
||||
|
||||
type Record struct {
|
||||
Name string
|
||||
Surname string
|
||||
Tel []Telephone
|
||||
}
|
||||
|
||||
type Telephone struct {
|
||||
Mobile bool
|
||||
Number string
|
||||
}
|
||||
|
||||
func loadFromXML(filename string, key interface{}) error {
|
||||
in, err := os.Open(filename)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
decodeXML := xml.NewDecoder(in)
|
||||
err = decodeXML.Decode(key)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
in.Close()
|
||||
return nil
|
||||
}
|
||||
|
||||
func main() {
|
||||
arguments := os.Args
|
||||
if len(arguments) == 1 {
|
||||
fmt.Println("Please provide a filename!")
|
||||
return
|
||||
}
|
||||
|
||||
filename := arguments[1]
|
||||
|
||||
var myRecord Record
|
||||
err := loadFromXML(filename, &myRecord)
|
||||
if err == nil {
|
||||
fmt.Println("XML:", myRecord)
|
||||
} else {
|
||||
fmt.Println(err)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue