From b668476c47cfdf98ae8a8fbf4cdef62548fa8180 Mon Sep 17 00:00:00 2001 From: Marcell Mars Date: Wed, 23 Mar 2022 23:48:42 +0100 Subject: [PATCH] initial parsing of zotero's rdf with etree --- cmd/build.go | 19 +++++++++++-------- cmd/commoners.go | 1 - 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/cmd/build.go b/cmd/build.go index 3aebb3b..3239142 100644 --- a/cmd/build.go +++ b/cmd/build.go @@ -2,7 +2,7 @@ package cmd import ( "fmt" - "strings" + "os" "accorder/pkg/calibre" @@ -61,13 +61,16 @@ should be enough for the next successful build).`, panic(err) } root := doc.SelectElement("rdf:RDF") - for _, bib := range root.FindElements("//*") { - if bib.Space == "bib" { - if strings.ToLower(bib.Tag) == "book" { - fmt.Println(bib.Tag) - fmt.Printf("%#v\n\n", bib) - } - } + for _, z := range root.FindElements("[link:type]") { + doc := etree.NewDocument() + doc.SetRoot(z.Copy()) + fmt.Println("~ ~ ~ ~") + fmt.Println(doc.WriteTo(os.Stdout)) + elm := root.FindElement(fmt.Sprintf("[@rdf:resource='%s']", z.SelectAttr("rdf:about").Value)) + doc.SetRoot(elm.Parent().Copy()) + fmt.Println("+++++") + fmt.Println(doc.WriteTo(os.Stdout)) + fmt.Println("~ ~ ~ ~") } calibre.RenderStandaloneApp(calibrePath, librarianName, libraryUUID, librarySecret, jsonPath) }, diff --git a/cmd/commoners.go b/cmd/commoners.go index 6b95eaa..5c91b84 100644 --- a/cmd/commoners.go +++ b/cmd/commoners.go @@ -3,7 +3,6 @@ package cmd import ( "encoding/json" "fmt" - "log" "os" "path/filepath"