summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSilvan Jegen <s.jegen@gmail.com>2016-09-13 20:38:17 +0200
committerSilvan Jegen <s.jegen@gmail.com>2016-09-13 20:38:17 +0200
commit4a0fcd9b9751c2999459d4c93db9a2a0ddb7fa66 (patch)
tree4611366b7955572fdb06d1b789b9fe407a621c4b
parent6c312b95ba3e8d53647057dc92fa3ba2feab8c5b (diff)
Add goencxml
-rw-r--r--Makefile5
-rw-r--r--goencxml.go36
2 files changed, 40 insertions, 1 deletions
diff --git a/Makefile b/Makefile
index a33f93a..2ccc9ea 100644
--- a/Makefile
+++ b/Makefile
@@ -2,7 +2,7 @@ CC = gcc
CFLAGS = -Wall -O2
-all: mxml ezxml yxml sxmlc
+all: mxml ezxml yxml sxmlc goencxml
mxml: mxml.c
$(CC) $(CFLAGS) -lmxml -pthread -o mxml mxml.c
@@ -16,6 +16,9 @@ yxml: yxml.c yxmllib.o
sxmlc: sxmlc.c sxmlclib.o
$(CC) $(CFLAGS) -o sxmlc sxmlc.c sxmlclib.o
+goencxml: goencxml.go
+ go build goencxml.go
+
ezxmllib.o: ezxmllib.c
yxmllib.o: yxmllib.c
diff --git a/goencxml.go b/goencxml.go
new file mode 100644
index 0000000..cedbb9c
--- /dev/null
+++ b/goencxml.go
@@ -0,0 +1,36 @@
+package main
+
+import (
+ "bufio"
+ "encoding/xml"
+ "fmt"
+ "os"
+)
+
+type article struct {
+ Title string `xml:"article>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()
+ }
+}