maybe etree output is already good enough for simplest struct to

unmarshal to
This commit is contained in:
Marcell Mars 2022-04-03 01:27:13 +02:00
parent 71c0046807
commit 9fee37b37c
1 changed files with 25 additions and 0 deletions

View File

@ -1,7 +1,9 @@
package cmd
import (
"encoding/xml"
"fmt"
"log"
"os"
"accorder/pkg/calibre"
@ -11,6 +13,18 @@ import (
"github.com/spf13/viper"
)
type FileAttachment struct {
XMLName xml.Name `xml:"resource"`
Path string `xml:"resource,attr"`
}
type ZoteroAttachment struct {
XMLName xml.Name `xml:"Attachment"`
ReferenceID string `xml:"about,attr"`
FileAttachment FileAttachment
FileType string `xml:"type"`
}
var buildCmd = &cobra.Command{
Use: "build",
Short: "Build standalone, portable webapp from Calibre library.",
@ -60,6 +74,7 @@ should be enough for the next successful build).`,
if err := doc.ReadFromFile(bibtexPath); err != nil {
panic(err)
}
var zoteroAttachment ZoteroAttachment
root := doc.SelectElement("rdf:RDF")
for _, z := range root.FindElements("[name()='link:type']") {
doc := etree.NewDocument()
@ -67,6 +82,16 @@ should be enough for the next successful build).`,
if z.Text() != "application/pdf" {
continue
}
doc.WriteTo(os.Stdout)
b, err := doc.WriteToBytes()
if err != nil {
log.Fatal(err)
}
if err := xml.Unmarshal(b, &zoteroAttachment); err != nil {
log.Fatalln(err)
}
fmt.Printf("\nZOTEROATTACHMENT: %#v\n", zoteroAttachment)
fmt.Println(z.Text())
fmt.Println("~ ~ ~ ~")
fmt.Println(doc.WriteTo(os.Stdout))