-
Notifications
You must be signed in to change notification settings - Fork 13
/
ncx.go
47 lines (38 loc) · 878 Bytes
/
ncx.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// Copyright 2012 Ruben Pollan <[email protected]>
// Use of this source code is governed by a LGPL licence
// version 3 or later that can be found in the LICENSE file.
package epubgo
import (
"io"
)
type xmlNCX struct {
NavMap []navpoint `xml:"navMap>navPoint"`
}
type navpoint struct {
Text string `xml:"navLabel>text"`
Content content `xml:"content"`
NavPoint []navpoint `xml:"navPoint"`
}
type content struct {
Src string `xml:"src,attr"`
}
func parseNCX(ncx io.Reader) (*xmlNCX, error) {
var n xmlNCX
err := decodeXML(ncx, &n)
if err != nil {
return nil, err
}
return &n, nil
}
func (ncx xmlNCX) navMap() []navpoint {
return ncx.NavMap
}
func (point navpoint) Title() string {
return point.Text
}
func (point navpoint) URL() string {
return point.Content.Src
}
func (point navpoint) Children() []navpoint {
return point.NavPoint
}