blob: b4fb7cf7aded5ec6bc5e9650d1beda9db3eab243 (
plain)
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
|
package main
import (
"bufio"
"encoding/xml"
"fmt"
"os"
)
type article struct {
Title string `xml:"front>article-meta>title-group>article-title"`
}
func process(r *bufio.Reader) {
var a article
err := xml.NewDecoder(r).Decode(&a)
if err != nil {
fmt.Fprintf(os.Stderr, "Error when decoding XML file %q\n", err)
}
fmt.Printf("article-title: %s\n", a.Title)
}
func main() {
for _, arg := range os.Args[1:] {
file, err := os.Open(arg)
if err != nil {
fmt.Fprintf(os.Stderr, "Error when opening file %q\n", arg)
os.Exit(1)
}
r := bufio.NewReader(file)
process(r)
file.Close()
}
}
|