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() } }