Пример #1
0
func main() {
	flag.Parse()
	fmt.Println(flag.Arg(0))
	fout, err := os.OpenFile(*outfilename, os.O_CREATE|os.O_RDWR, 0666)
	if err != nil {
		panic(err)
	}
	defer fout.Close()
	f, err := os.Open(flag.Arg(0))
	if err != nil {
		panic(err)
	}
	defer f.Close()

	fmt.Fprintln(fout, `<?xml version="1.0" encoding="UTF-8"?>`)
	fmt.Fprintln(fout, "<documentset>")
	mr := gomarc.NewReader(f)
	for mr.Next() {
		xml := xmlRecord(mr)
		fmt.Fprintln(fout, xml)
	}
	fmt.Fprintln(fout, "</documentset>")
	if mr.Err != nil {
		panic(mr.Err)
	}
}
Пример #2
0
func processFile(filename string, fout *os.File) error {
	fmt.Printf("Processing '%s'...\n", filename)

	f, err := os.Open(filename)
	if err != nil {
		return err
	}
	defer f.Close()

	nrec := 0
	mr := gomarc.NewReader(f)
	for mr.Next() {
		edges := edgesFromRecord(mr)
		if edges != nil {
			fmt.Fprintln(fout, strings.Join(edges, "\n"))
			nrec += len(edges)
		}
	}
	if mr.Err != nil {
		return mr.Err
	}
	fmt.Printf("  %d edges\n", nrec)
	return nil
}