gofb2

package module
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 9, 2021 License: MIT Imports: 7 Imported by: 0

README

GoFB2

GoFB2 is golang structures for parse .fb2 book format. It's based on XML schema https://github.com/gribuser/fb2.

Usage example:

package main

import (
	"encoding/xml"
	"fmt"
	"io/ioutil"
	"strings"

	fb2 "github.com/Grey-Fox/gofb2"
)

func printContent(cont ...fb2.Contenter) {
	for _, c := range cont {
		switch e := c.(type) {
		case fb2.CharData:
			fmt.Printf(strings.ReplaceAll(string(e.GetText()), "\t", ""))
		case *fb2.P:
			printContent(e.Content...)
			fmt.Println()
		case fb2.EmptyLine:
			fmt.Println()
		case *fb2.Poem:
			if e.Title != nil {
				printContent(e.Title)
			}
			printContent(e.GetContent()...)
		case *fb2.Cite:
			fmt.Printf("> ")
			printContent(e.GetContent()...)
			for _, a := range e.TextAuthor {
				fmt.Printf("(c) ")
				printContent(a)
			}
			fmt.Println()
		default:
			printContent(c.GetContent()...)
		}
	}
}

func printSection(s *fb2.Section) {
	for _, s := range s.Sections {
		printSection(s)
	}
	printContent(s.Content...)
}

func main() {
	data, err := ioutil.ReadFile("example.fb2")
	check(err)

	v := fb2.FictionBook{}
	check(xml.Unmarshal([]byte(data), &v))
	printContent(v.Description.TitleInfo.Annotation)
	printSection(v.Body.Sections[0])
}

func check(e error) {
	if e != nil {
		panic(e)
	}
}

Parse only description:

package main

import (
	"bytes"
	"encoding/xml"
	"fmt"
	"io"
	"io/ioutil"

	fb2 "github.com/Grey-Fox/gofb2"
	"golang.org/x/net/html/charset"
)

func parseDescription(r io.Reader) (*fb2.FictionBook, error) {
	v := &fb2.FictionBook{}
	p := fb2.NewParser(v)
	decoder := xml.NewDecoder(r)
	decoder.CharsetReader = charset.NewReaderLabel

	for {
		token, _ := decoder.Token()
		p.ParseToken(token)
		if e, ok := token.(xml.EndElement); ok && e.Name.Local == "description" {
			break
		}
	}

	return v, nil
}

func main() {
	data, _ := ioutil.ReadFile("example.fb2")

	reader := bytes.NewReader(data)
	v, _ := parseDescription(reader)
	fmt.Println(
		v.Description.TitleInfo.Authors[0].FirstName.Value,
		v.Description.TitleInfo.Authors[0].MiddleName.Value,
		v.Description.TitleInfo.Authors[0].LastName.Value,
	)
}

Use libxml2 for parse:

package main

import (
	"bytes"
	"encoding/xml"
	"fmt"
	"io/ioutil"

	fb2 "github.com/Grey-Fox/gofb2"
	"github.com/lestrrat-go/libxml2/parser"
	"github.com/lestrrat-go/libxml2/types"
)

func parse(doc types.Document) (*fb2.FictionBook, error) {
	var walk func(types.NodeList)

	v := &fb2.FictionBook{}
	p := fb2.NewParser(v)
	walk = func(nodes types.NodeList) {
		for _, n := range nodes {
			if e, ok := n.(types.Element); ok {
				attrs, _ := e.Attributes()
				xmlAttrs := make([]xml.Attr, len(attrs))
				for i, a := range attrs {
					xmlAttrs[i] = xml.Attr{
						Name:  xml.Name{Local: a.NodeName()},
						Value: a.Value(),
					}
				}
				st := xml.StartElement{
					Name: xml.Name{Local: e.NodeName()},
					Attr: xmlAttrs,
				}
				p.ParseToken(st)

				cn, _ := e.ChildNodes()
				walk(cn)

				p.ParseToken(xml.EndElement{Name: xml.Name{Local: n.NodeName()}})
			} else {
				p.ParseToken(xml.CharData(n.NodeValue()))
			}
		}
	}

	cn, _ := doc.ChildNodes()
	walk(cn)

	return v, nil
}

func main() {
	data, _ := ioutil.ReadFile("example.fb2")

	reader := bytes.NewReader(data)
	p := parser.New()
	doc, _ := p.ParseReader(reader)
	v, _ := parse(doc)

	fmt.Println(
		v.Description.TitleInfo.Authors[0].FirstName.Value,
		v.Description.TitleInfo.Authors[0].MiddleName.Value,
		v.Description.TitleInfo.Authors[0].LastName.Value,
	)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Annotation

type Annotation struct {
	ID   string `xml:"id,omitempty"`
	Lang string `xml:"http://www.w3.org/XML/1998/namespace lang,attr,omitempty"`
	// contains filtered or unexported fields
}

Annotation https://github.com/gribuser/fb2/blob/14b5fcc6/FictionBook.xsd#L381 A cut-down version of "section" used in annotations

func (Annotation) GetContent

func (c Annotation) GetContent() []Contenter

GetContent return content

func (Annotation) GetText

func (c Annotation) GetText() []byte

GetText return nil All text in CharData type

func (*Annotation) UnmarshalXML

func (a *Annotation) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

UnmarshalXML unmarshal xml to FictionBook struct

type Author

type Author struct {
	FirstName  *TextField `xml:"first-name,omitempty"`
	MiddleName *TextField `xml:"middle-name,omitempty"`
	LastName   *TextField `xml:"last-name,omitempty"`
	Nickname   *TextField `xml:"nickname,omitempty"`
	HomePages  []string   `xml:"home-page,omitempty"`
	Emails     []string   `xml:"email,omitempty"`
	ID         string     `xml:"id,omitempty"`
	// contains filtered or unexported fields
}

Author https://github.com/gribuser/fb2/blob/14b5fcc6/FictionBook.xsd#L233 Information about a single author

func (*Author) GetXMLName

func (n *Author) GetXMLName() xml.Name

func (*Author) SetXMLName

func (n *Author) SetXMLName(name xml.Name)

func (*Author) UnmarshalXML

func (a *Author) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

UnmarshalXML unmarshal XML

type Binary

type Binary struct {
	ID          string `xml:"id,attr"`
	ContentType string `xml:"content-type,attr"`
	Value       []byte `xml:",chardata"`
	// contains filtered or unexported fields
}

Binary https://github.com/gribuser/fb2/blob/14b5fcc6/FictionBook.xsd#L217 Any binary data that is required for the presentation of this book in base64 format. Currently only images are used

func (*Binary) GetXMLName

func (n *Binary) GetXMLName() xml.Name

func (*Binary) SetXMLName

func (n *Binary) SetXMLName(name xml.Name)

func (*Binary) UnmarshalXML

func (b *Binary) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

UnmarshalXML decode from base64

type Body

type Body struct {

	// Image to be displayed at the top of this section
	Image *Image `xml:"image,omitempty"`

	// A fancy title for the entire book, should be used if the simple text version
	// in "description"; is not adequate, e.g. the book title has multiple paragraphs
	// and/or character styles
	Title *Title `xml:"title,omitempty"`

	// Epigraph(s) for the entire book, if any
	Epigraphs []*Epigraph `xml:"epigraph,omitempty"`

	Sections []*Section `xml:"section"`

	Lang string `xml:"http://www.w3.org/XML/1998/namespace lang,attr,omitempty"`
	// contains filtered or unexported fields
}

Body https://github.com/gribuser/fb2/blob/14b5fcc6/FictionBook.xsd#L31 Main content of the book, multiple bodies are used for additional information, like footnotes, that do not appear in the main book flow (extended from this class). The first body is presented to the reader by default, and content in the other bodies should be accessible by hyperlinks.

func (*Body) GetXMLName

func (n *Body) GetXMLName() xml.Name

func (*Body) SetXMLName

func (n *Body) SetXMLName(name xml.Name)

func (*Body) UnmarshalXML

func (b *Body) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

UnmarshalXML unmarshal XML to Body

type CharData

type CharData xml.CharData

A CharData represents raw text

func (CharData) GetContent

func (c CharData) GetContent() []Contenter

GetContent return nil, because CharData contains only raw text

func (CharData) GetText

func (c CharData) GetText() []byte

GetText return text

func (CharData) GetXMLName

func (c CharData) GetXMLName() xml.Name

GetXMLName return empty string for raw text

type Cite

type Cite struct {
	ID         string `xml:"id,omitempty"`
	Lang       string `xml:"http://www.w3.org/XML/1998/namespace lang,attr,omitempty"`
	TextAuthor []*P   `xml:"text-author,omitempty"`
	// contains filtered or unexported fields
}

Cite https://github.com/gribuser/fb2/blob/14b5fcc6/FictionBook.xsd#L304 A citation with an optional citation author at the end

func (Cite) GetContent

func (c Cite) GetContent() []Contenter

GetContent return content

func (Cite) GetText

func (c Cite) GetText() []byte

GetText return nil All text in CharData type

func (*Cite) UnmarshalXML

func (c *Cite) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

UnmarshalXML unmarshal XML to Cite

type Contenter

type Contenter interface {
	GetXMLName() xml.Name
	GetContent() []Contenter
	GetText() []byte
}

Contenter provide interface for tag content

type Coverpage

type Coverpage struct {
	Image *InlineImage `xml:"image"`
	// contains filtered or unexported fields
}

Coverpage https://github.com/gribuser/fb2/blob/14b5fcc6/FictionBook.xsd#L621

func (*Coverpage) GetXMLName

func (n *Coverpage) GetXMLName() xml.Name

func (*Coverpage) SetXMLName

func (n *Coverpage) SetXMLName(name xml.Name)

func (*Coverpage) UnmarshalXML

func (c *Coverpage) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

UnmarshalXML unmarshal XML

type CustomInfo

type CustomInfo struct {
	TextField
	InfoType string `xml:"info-type,attr"`
}

CustomInfo https://github.com/gribuser/fb2/blob/14b5fcc6/FictionBook.xsd#L191

func (*CustomInfo) GetXMLName

func (n *CustomInfo) GetXMLName() xml.Name

func (*CustomInfo) SetXMLName

func (n *CustomInfo) SetXMLName(name xml.Name)

func (*CustomInfo) UnmarshalXML

func (ci *CustomInfo) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

UnmarshalXML unmarshal XML

type Date

type Date struct {
	Value    *XMLDate `xml:"value,attr,omitempty"`
	Lang     string   `xml:"http://www.w3.org/XML/1998/namespace lang,attr,omitempty"`
	StrValue string   `xml:",chardata"`
	// contains filtered or unexported fields
}

Date https://github.com/gribuser/fb2/blob/14b5fcc6/FictionBook.xsd#L262 A human readable date, maybe not exact, with an optional computer readable variant

func (*Date) GetXMLName

func (n *Date) GetXMLName() xml.Name

func (*Date) SetXMLName

func (n *Date) SetXMLName(name xml.Name)

func (*Date) UnmarshalXML

func (d *Date) UnmarshalXML(dec *xml.Decoder, start xml.StartElement) error

UnmarshalXML unmarshal XML

type Description

type Description struct {

	// Generic information about the book
	TitleInfo *TitleInfo `xml:"title-info"`

	// Generic information about the original book (for translations)
	SrcTitleInfo *TitleInfo `xml:"src-title-info,omitempty"`

	// Information about this particular (xml) document
	DocumentInfo *DocumentInfo `xml:"document-info"`

	// Information about some paper/outher published document,
	// that was used as a source of this xml document
	PublishInfo *PublishInfo `xml:"publish-info,omitempty"`

	// Any other information about the book/document
	// that didn't fit in the above groups
	CustomInfo []*CustomInfo `xml:"custom-info,omitempty"`

	// Describes, how the document should be presented to end-user, what parts
	// are free, what parts should be sold and what price should be used
	Output []*ShareInstruction `xml:"output,omitempty"`
	// contains filtered or unexported fields
}

Description https://github.com/gribuser/fb2/blob/14b5fcc6/FictionBook.xsd#L90

func (*Description) GetXMLName

func (n *Description) GetXMLName() xml.Name

func (*Description) SetXMLName

func (n *Description) SetXMLName(name xml.Name)

func (*Description) UnmarshalXML

func (d *Description) UnmarshalXML(dec *xml.Decoder, start xml.StartElement) error

UnmarshalXML unmarshal XML

type DocGenerationInstruction

type DocGenerationInstruction string

DocGenerationInstruction https://github.com/gribuser/fb2/blob/14b5fcc6/FictionBook.xsd#L671 List of instructions to process sections (allow|deny|require)

type DocumentInfo

type DocumentInfo struct {

	// Author(s) of this particular document
	Authors []*Author `xml:"author"`

	// Any software used in preparation of this document, in free format
	ProgramUsed *TextField `xml:"program-used"`

	// Date this document was created, same guidelines as in the <title-info> section apply
	Date *Date `xml:"date"`

	// Source URL if this document is a conversion of some other (online) document
	SrcURLs []string `xml:"src-url"`

	// Author of the original (online) document, if this is a conversion
	SrcOcr *TextField `xml:"src-ocr"`

	// this is a unique identifier for a document. this must not change
	ID string `xml:"id"`

	// Document version, in free format, should be incremented if the document is changed and re-released to the public
	Version float64 `xml:"version"`

	// Short description for all changes made to this document, like "Added missing chapter 6", in free form.
	History *Annotation `xml:"history"`

	// Owner of the fb2 document copyrights
	Publishers []*Author `xml:"publisher"`
	// contains filtered or unexported fields
}

DocumentInfo https://github.com/gribuser/fb2/blob/14b5fcc6/FictionBook.xsd#L102

func (*DocumentInfo) GetXMLName

func (n *DocumentInfo) GetXMLName() xml.Name

func (*DocumentInfo) SetXMLName

func (n *DocumentInfo) SetXMLName(name xml.Name)

func (*DocumentInfo) UnmarshalXML

func (di *DocumentInfo) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

UnmarshalXML unmarshal XML

type EmptyLine

type EmptyLine struct {
	XMLName xml.Name `xml:"empty-line"`
	// contains filtered or unexported fields
}

EmptyLine -- dummy struct for <empty-line/>

func (EmptyLine) GetContent

func (e EmptyLine) GetContent() []Contenter

type Epigraph

type Epigraph struct {
	ID         string `xml:"id,omitempty"`
	TextAuthor []*P   `xml:"text-author,omitempty"`
	// contains filtered or unexported fields
}

Epigraph https://github.com/gribuser/fb2/blob/14b5fcc6/FictionBook.xsd#L366 An epigraph

func (Epigraph) GetContent

func (c Epigraph) GetContent() []Contenter

GetContent return content

func (Epigraph) GetText

func (c Epigraph) GetText() []byte

GetText return nil All text in CharData type

func (*Epigraph) UnmarshalXML

func (ep *Epigraph) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

UnmarshalXML unmarshal XML to Epigraph

type FictionBook

type FictionBook struct {
	Stylesheet  []*Stylesheet
	Description *Description
	Body        *Body
	NotesBody   *NotesBody
	Binary      []*Binary
	// contains filtered or unexported fields
}

FictionBook describe book scheme based on https://github.com/gribuser/fb2/blob/14b5fcc6/FictionBook.xsd#L71

func (*FictionBook) GetXMLName

func (n *FictionBook) GetXMLName() xml.Name

func (*FictionBook) SetXMLName

func (n *FictionBook) SetXMLName(name xml.Name)

func (*FictionBook) UnmarshalXML

func (f *FictionBook) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

UnmarshalXML unmarshal XML

type Genre

type Genre struct {
	Match *int   `xml:"match,attr,omitempty"`
	Genre string `xml:",chardata"`
	// contains filtered or unexported fields
}

Genre https://github.com/gribuser/fb2/blob/14b5fcc6/FictionBook.xsd#L581

func (*Genre) GetXMLName

func (n *Genre) GetXMLName() xml.Name

func (*Genre) SetXMLName

func (n *Genre) SetXMLName(name xml.Name)

func (*Genre) UnmarshalXML

func (g *Genre) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

UnmarshalXML unmarshal XML

type Image

type Image struct {
	XlinkType string `xml:"http://www.w3.org/1999/xlink type,attr,omitempty"`
	XlinkHref string `xml:"http://www.w3.org/1999/xlink href,attr,omitempty"`
	Alt       string `xml:"alt,attr,omitempty"`
	Title     string `xml:"title,attr,omitempty"`
	ID        string `xml:"id,attr,omitempty"`
	// contains filtered or unexported fields
}

Image https://github.com/gribuser/fb2/blob/14b5fcc6/FictionBook.xsd#L283 An empty element with an image name as an attribute

func (Image) GetContent

func (e Image) GetContent() []Contenter

type InlineImage

type InlineImage struct {
	XlinkType string `xml:"http://www.w3.org/1999/xlink type,attr,omitempty"`
	XlinkHref string `xml:"http://www.w3.org/1999/xlink href,attr,omitempty"`
	Alt       string `xml:"alt,attr,omitempty"`
	// contains filtered or unexported fields
}

InlineImage https://github.com/gribuser/fb2/blob/14b5fcc6/FictionBook.xsd#L712 It's Contenter, but has no text or "child" content

func (InlineImage) GetContent

func (e InlineImage) GetContent() []Contenter

func (*InlineImage) UnmarshalXML

func (i *InlineImage) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

UnmarshalXML unmarshal XML to InlineImage

type Link struct {
	StyleLinkType
	XlinkType string `xml:"http://www.w3.org/1999/xlink type,attr,omitempty"`
	XlinkHref string `xml:"http://www.w3.org/1999/xlink href,attr"`
	Type      string `xml:"type,attr,omitempty"`
}

Link https://github.com/gribuser/fb2/blob/14b5fcc6/FictionBook.xsd#L488 Generic hyperlinks. Cannot be nested. Footnotes should be implemented by links referring to additional bodies in the same document

func (*Link) UnmarshalXML

func (l *Link) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

UnmarshalXML unmarshal XML to Link

type NamedStyleType

type NamedStyleType struct {
	StyleType
	Name string `xml:"name,attr"`
}

NamedStyleType https://github.com/gribuser/fb2/blob/14b5fcc6/FictionBook.xsd#L470 Markup

func (*NamedStyleType) UnmarshalXML

func (s *NamedStyleType) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

UnmarshalXML unmarshal XML to NamedStyleType

type Node

type Node interface {
	SetXMLName(xml.Name)
	GetXMLName() xml.Name
	// contains filtered or unexported methods
}

Node define the basic interface for XML nodes

type NotesBody

type NotesBody struct {
	Body
	Name string `xml:"name,attr"`
}

NotesBody https://github.com/gribuser/fb2/blob/14b5fcc6/FictionBook.xsd#L55 Body for footnotes, content is mostly similar to base type and may (!) be rendered in the pure environment "as is". Advanced reader should treat section[2]/section as endnotes, all other stuff as footnotes

func (*NotesBody) GetXMLName

func (n *NotesBody) GetXMLName() xml.Name

func (*NotesBody) SetXMLName

func (n *NotesBody) SetXMLName(name xml.Name)

func (*NotesBody) UnmarshalXML

func (b *NotesBody) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

UnmarshalXML unmarshal XML to NotesBody

type OutPutDocument

type OutPutDocument struct {
	Name   string                   `xml:"name,attr"`
	Create DocGenerationInstruction `xml:"create,attr,omitempty"`
	Price  float64                  `xml:"price,attr,omitempty"`
	Parts  []*PartShareInstruction  `xml:"part,omitempty"`
	// contains filtered or unexported fields
}

OutPutDocument https://github.com/gribuser/fb2/blob/14b5fcc6/FictionBook.xsd#L689 Selector for output documents. Defines, which rule to apply to any specific output documents

func (*OutPutDocument) GetXMLName

func (n *OutPutDocument) GetXMLName() xml.Name

func (*OutPutDocument) SetXMLName

func (n *OutPutDocument) SetXMLName(name xml.Name)

func (*OutPutDocument) UnmarshalXML

func (od *OutPutDocument) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

UnmarshalXML unmarshal XML

type P

type P struct {
	StyleType
	ID    string `xml:"id,attr,omitempty"`
	Style string `xml:"style,attr,omitempty"`
}

P https://github.com/gribuser/fb2/blob/14b5fcc6/FictionBook.xsd#L293 A basic paragraph, may include simple formatting inside

func (*P) UnmarshalXML

func (p *P) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

UnmarshalXML unmarshal XML to P

type Parser

type Parser struct {
	// contains filtered or unexported fields
}

Parser parse xml document

func NewParser

func NewParser(n Node) *Parser

NewParser return new parser

func (*Parser) Parse

func (p *Parser) Parse(d *xml.Decoder, start xml.StartElement) error

Parse xml document

func (*Parser) ParseToken

func (p *Parser) ParseToken(token xml.Token) error

ParseToken parse one xml.Token. StartElement, EndElement or CharData.

type PartShareInstruction

type PartShareInstruction struct {
	XlinkType string                   `xml:"http://www.w3.org/1999/xlink type,attr,omitempty"`
	XlinkHref string                   `xml:"http://www.w3.org/1999/xlink href,attr"`
	Include   DocGenerationInstruction `xml:"include,attr"`
	// contains filtered or unexported fields
}

PartShareInstruction https://github.com/gribuser/fb2/blob/14b5fcc6/FictionBook.xsd#L681 Pointer to specific document section, explaining how to deal with it

func (*PartShareInstruction) GetXMLName

func (n *PartShareInstruction) GetXMLName() xml.Name

func (*PartShareInstruction) SetXMLName

func (n *PartShareInstruction) SetXMLName(name xml.Name)

func (*PartShareInstruction) UnmarshalXML

func (psi *PartShareInstruction) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

UnmarshalXML unmarshal XML

type Poem

type Poem struct {
	// Poem title
	XMLName xml.Name `xml:"poem"`
	Title   *Title   `xml:"title,omitempty"`

	// Poem epigraph(s), if any
	Epigraphs []*Epigraph `xml:"epigraph,omitempty"`
	// contains filtered or unexported fields
}

Poem https://github.com/gribuser/fb2/blob/14b5fcc6/FictionBook.xsd#L321 A poem

func (Poem) GetContent

func (c Poem) GetContent() []Contenter

GetContent return content

func (Poem) GetText

func (c Poem) GetText() []byte

GetText return nil All text in CharData type

func (*Poem) UnmarshalXML

func (p *Poem) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

UnmarshalXML unmarshal XML to StyleType

type PublishInfo

type PublishInfo struct {

	// Original (paper) book name
	BookName *TextField `xml:"book-name,omitempty"`
	// Original (paper) book publisher
	Publisher *TextField `xml:"publisher,omitempty"`
	// City where the original (paper) book was published
	City *TextField `xml:"city,omitempty"`
	// Year of the original (paper) publication
	Year string `xml:"year,omitempty"`

	ISBN      *TextField  `xml:"isbn,omitempty"`
	Sequences []*Sequence `xml:"sequence,omitempty"`
	// contains filtered or unexported fields
}

PublishInfo https://github.com/gribuser/fb2/blob/14b5fcc6/FictionBook.xsd#L160

func (*PublishInfo) GetXMLName

func (n *PublishInfo) GetXMLName() xml.Name

func (*PublishInfo) SetXMLName

func (n *PublishInfo) SetXMLName(name xml.Name)

func (*PublishInfo) UnmarshalXML

func (pi *PublishInfo) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

UnmarshalXML unmarshal XML

type Section

type Section struct {
	// Section's title
	Title *Title `xml:"title,omitempty"`

	// Epigraph(s) for this section
	Epigraphs []*Epigraph `xml:"epigraph,omitempty"`

	// Image to be displayed at the top of this section
	Image *Image `xml:"image,omitempty"`

	// Annotation for this section, if any
	Annotation *Annotation `xml:"annotation,omitempty"`

	// or child Sections
	Sections []*Section `xml:"section,omitempty"`

	ID   string `xml:"id,omitempty"`
	Lang string `xml:"http://www.w3.org/XML/1998/namespace lang,attr,omitempty"`
	// contains filtered or unexported fields
}

Section https://github.com/gribuser/fb2/blob/14b5fcc6/FictionBook.xsd#L396 A basic block of a book, can contain more child sections or textual content

func (Section) GetContent

func (c Section) GetContent() []Contenter

GetContent return content

func (Section) GetText

func (c Section) GetText() []byte

GetText return nil All text in CharData type

func (*Section) UnmarshalXML

func (s *Section) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

UnmarshalXML unmarshal XML to Section

type Sequence

type Sequence struct {
	Sequences []*Sequence `xml:"sequence,omitempty"`
	Name      string      `xml:"name,attr"`
	Number    int         `xml:"number,attr"`
	// contains filtered or unexported fields
}

Sequence https://github.com/gribuser/fb2/blob/14b5fcc6/FictionBook.xsd#L521 Book sequences

func (*Sequence) GetXMLName

func (n *Sequence) GetXMLName() xml.Name

func (*Sequence) SetXMLName

func (n *Sequence) SetXMLName(name xml.Name)

func (*Sequence) UnmarshalXML

func (s *Sequence) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

UnmarshalXML unmarshal XML

type ShareInstruction

type ShareInstruction struct {
	Mode                ShareMode                `xml:"mode,attr"`
	IncludeAll          DocGenerationInstruction `xml:"include-all,attr"`
	Price               float64                  `xml:"price,attr,omitempty"`
	Currency            string                   `xml:"currency,attr,omitempty"`
	Parts               []*PartShareInstruction  `xml:"part,omitempty"`
	OutputDocumentClass []*OutPutDocument        `xml:"output-document-class,omitempty"`
	// contains filtered or unexported fields
}

ShareInstruction https://github.com/gribuser/fb2/blob/14b5fcc6/FictionBook.xsd#L649 In-document instruction for generating output free and payed documents

func (*ShareInstruction) GetXMLName

func (n *ShareInstruction) GetXMLName() xml.Name

func (*ShareInstruction) SetXMLName

func (n *ShareInstruction) SetXMLName(name xml.Name)

func (*ShareInstruction) UnmarshalXML

func (si *ShareInstruction) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

UnmarshalXML unmarshal XML

type ShareMode

type ShareMode string

ShareMode https://github.com/gribuser/fb2/blob/14b5fcc6/FictionBook.xsd#L662 Modes for document sharing (free|paid for now)

type Stanza

type Stanza struct {
	Lang     string `xml:"http://www.w3.org/XML/1998/namespace lang,attr,omitempty"`
	Title    *Title `xml:"title,omitempty"`
	Subtitle *P     `xml:"subtitle,omitempty"`
	// An individual line in a stanza
	V []*P `xml:"v"`
	// contains filtered or unexported fields
}

Stanza https://github.com/gribuser/fb2/blob/14b5fcc6/FictionBook.xsd#L338 Each poem should have at least one stanza. Stanzas are usually separated with empty lines by user agents.

func (Stanza) GetContent

func (s Stanza) GetContent() []Contenter

GetContent for Contenter interface

func (Stanza) GetText

func (e Stanza) GetText() []byte

func (Stanza) GetXMLName

func (e Stanza) GetXMLName() xml.Name

type StyleLinkType

type StyleLinkType struct {
	// contains filtered or unexported fields
}

StyleLinkType https://github.com/gribuser/fb2/blob/14b5fcc6/FictionBook.xsd#L506 Markup

func (*StyleLinkType) UnmarshalXML

func (s *StyleLinkType) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

UnmarshalXML unmarshal XML to StyleType

type StyleType

type StyleType struct {
	Lang string `xml:"http://www.w3.org/XML/1998/namespace lang,attr,omitempty"`
	// contains filtered or unexported fields
}

StyleType https://github.com/gribuser/fb2/blob/14b5fcc6/FictionBook.xsd#L453 Markup

func (*StyleType) UnmarshalXML

func (s *StyleType) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

UnmarshalXML unmarshal XML to StyleType

type Stylesheet

type Stylesheet struct {
	Type  string `xml:"type,attr"`
	Value []byte `xml:",innerxml"`
	// contains filtered or unexported fields
}

Stylesheet https://github.com/gribuser/fb2/blob/14b5fcc6/FictionBook.xsd#L77 This element contains an arbitrary stylesheet that is intepreted by a some processing programs, e.g. text/css stylesheets can be used by XSLT stylesheets to generate better looking html

func (*Stylesheet) GetXMLName

func (n *Stylesheet) GetXMLName() xml.Name

func (*Stylesheet) SetXMLName

func (n *Stylesheet) SetXMLName(name xml.Name)

func (*Stylesheet) UnmarshalXML

func (s *Stylesheet) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

UnmarshalXML unmarshal XML

type TD

type TD struct {
	StyleType
	ID      string `xml:"id,omitempty"`
	Style   string `xml:"style,attr,omitempty"`
	Colspan int    `xml:"colspan,attr,omitempty"`
	Rowspan int    `xml:"rowspan,attr,omitempty"`
	Align   string `xml:"align,attr,omitempty"`
	Valign  string `xml:"valign,attr,omitempty"`
}

TD https://github.com/gribuser/fb2/blob/14b5fcc6/FictionBook.xsd#L700

func (*TD) UnmarshalXML

func (t *TD) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

UnmarshalXML unmarshal XML to TD

type TR

type TR struct {
	Align string `xml:"align,attr,omitempty"`
	// contains filtered or unexported fields
}

TR https://github.com/gribuser/fb2/blob/14b5fcc6/FictionBook.xsd#L538

func (TR) GetContent

func (c TR) GetContent() []Contenter

GetContent return content

func (TR) GetText

func (c TR) GetText() []byte

GetText return nil All text in CharData type

func (*TR) UnmarshalXML

func (t *TR) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

UnmarshalXML unmarshal XML to Table

type Table

type Table struct {
	XMLName xml.Name `xml:"table"`
	TR      []*TR    `xml:"tr"`
	ID      string   `xml:"id,omitempty"`
	Style   string   `xml:"style,attr,omitempty"`
	// contains filtered or unexported fields
}

Table https://github.com/gribuser/fb2/blob/14b5fcc6/FictionBook.xsd#L532 Basic html-like tables

func (*Table) GetContent

func (t *Table) GetContent() []Contenter

GetContent for Contenter interface

func (Table) GetText

func (e Table) GetText() []byte

func (Table) GetXMLName

func (e Table) GetXMLName() xml.Name

type TextField

type TextField struct {
	Lang  string `xml:"http://www.w3.org/XML/1998/namespace lang,attr,omitempty"`
	Value string `xml:",chardata"`
	// contains filtered or unexported fields
}

TextField https://github.com/gribuser/fb2/blob/14b5fcc6/FictionBook.xsd#L255

func (*TextField) GetXMLName

func (n *TextField) GetXMLName() xml.Name

func (*TextField) SetXMLName

func (n *TextField) SetXMLName(name xml.Name)

func (*TextField) UnmarshalXML

func (t *TextField) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

UnmarshalXML unmarshal XML to TextField

type Title

type Title struct {
	Lang string `xml:"http://www.w3.org/XML/1998/namespace lang,attr,omitempty"`
	// contains filtered or unexported fields
}

Title https://github.com/gribuser/fb2/blob/14b5fcc6/FictionBook.xsd#L273 A title, used in sections, poems and body elements

func (Title) GetContent

func (c Title) GetContent() []Contenter

GetContent return content

func (Title) GetText

func (c Title) GetText() []byte

GetText return nil All text in CharData type

func (*Title) UnmarshalXML

func (t *Title) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

UnmarshalXML unmarshal XML to Title

type TitleInfo

type TitleInfo struct {

	// Genre of this book, with the optional match percentage
	Genres []*Genre `xml:"genre"`

	// Author(s) of this book
	Authors []*Author `xml:"author"`

	//Book title
	BookTitle *TextField `xml:"book-title"`

	// Annotation for this book
	Annotation *Annotation `xml:"annotation"`

	// Any keywords for this book, intended for use in search engines
	Keywords *TextField `xml:"keywords"`

	// Date this book was written, can be not exact, e.g. 1863-1867.
	// If an optional attribute is present, then it should contain some
	// computer-readable date from the interval for use by search and indexingengines
	Date *Date `xml:"date"`

	// Any coverpage items, currently only images
	Coverpage *Coverpage `xml:"coverpage"`

	// Book's language
	Lang string `xml:"lang"`

	// Book's source language if this is a translation
	SrcLang string `xml:"src-lang,omitempty"`

	// Translators if this is a translation
	Translators []*Author `xml:"translator"`

	// Any sequences this book might be part of
	Sequences []*Sequence `xml:"sequence"`
	// contains filtered or unexported fields
}

TitleInfo https://github.com/gribuser/fb2/blob/14b5fcc6/FictionBook.xsd#L570 Book (as a book opposite a document) description

func (*TitleInfo) GetXMLName

func (n *TitleInfo) GetXMLName() xml.Name

func (*TitleInfo) SetXMLName

func (n *TitleInfo) SetXMLName(name xml.Name)

func (*TitleInfo) UnmarshalXML

func (ti *TitleInfo) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

UnmarshalXML unmarshal XML

type XMLDate

type XMLDate struct {
	time.Time
}

XMLDate is a time.Time wrapper for correct unmarshalling

func (*XMLDate) UnmarshalXMLAttr

func (d *XMLDate) UnmarshalXMLAttr(attr xml.Attr) error

UnmarshalXMLAttr unmarshal xml xs:date to golang time.Time

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL