I've trimmed the program down to the following which exhibits the
behavior (on my computer at least.)
First, the input file (named rectest.ncx) :
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE ncx PUBLIC '-//NISO//DTD ncx 2005-1//EN'
'
http://www.daisy.org/z3986/2005/ncx-2005-1.dtd'>
<ncx xmlns="
http://www.daisy.org/z3986/2005/ncx/" version="2005-1"
xml:lang="en">
<navMap>
<navMap>
</ncx>
And the code that attempts to parse it (which I have named
rectest.go) :
package main
import (
"os"
"io"
"fmt"
"xml"
"strings" )
func main() {
type NavLabel struct { XMLName xml.Name "navLabel";
Text
string; }
type Content struct { XMLName xml.Name "content";
Src string "attr"; }
type NavPoint struct { XMLName xml.Name "navPoint";
Id string "attr";
PlayOrder string "attr";
NavLabel NavLabel;
Content Content;
// NavPoint []NavPoint;
}
type NavMap struct { XMLName xml.Name "navMap";
NavPoint
[]NavPoint; }
type Ncx struct { XMLName xml.Name "ncx";
Xmlns string "attr";
Version string "attr";
NavMap
NavMap; }
f, err := os.Open("rectest.ncx", os.O_RDONLY, 0);
if err != nil {
fmt.Printf("File Open Error\n")
return
}
defer f.Close();
d, err := f.Stat();
if err != nil {
fmt.Printf("File Stat Error\n")
return
}
buf := make([]byte, d.Size);
_, err = io.ReadFull(f, buf);
if err != nil {
fmt.Printf("File Read Error\n")
return
}
var eToc = Ncx{ NavMap: NavMap{ NavPoint: nil } }
xml.Unmarshal ( strings.NewReader(string(buf)) , &eToc )
fmt.Printf( "\nNavPoints:\n ")
for _,v:= range eToc.NavMap.NavPoint {
fmt.Printf( v.Id )
fmt.Printf( " - " )
fmt.Printf( v.PlayOrder)
fmt.Printf( " - " )
fmt.Printf( v.NavLabel.Text )
fmt.Printf( " - " )
fmt.Printf( v.Content.Src )
fmt.Printf( "\n " )
}
return
}
And for completeness sake, a Makefile:
include $(GOROOT)/src/Make.$(GOARCH)
ALL=rectest
all: $(ALL)
clean:
rm -rf *.[68] $(ALL)
%: %.go
$(GC) $*.go
$(LD) -o $@ $*.$O
When I compile with the comment in front of the recursive NavPoint in
place the compilation succeeds and I get the following output when
running the program:
host182-59:rectest cperkins$ make
8g rectest.go
8l -o rectest rectest.8
host182-59:rectest cperkins$ ./rectest
NavPoints:
np-3 - 3 - CHAPTER I - www.gutenberg.org@files@17...@17959-8-0.html#id00013
np-4 - 4 - CHAPTER II - www.gutenberg.org@files@17...@17959-8-0.html#id00061
When I compile with the comment in front of the recursive NavPoint
removed the compilation fails as follows:
host182-59:rectest cperkins$ make
8g rectest.go
rectest.go:24: invalid recursive type NavPoint
make: *** [rectest] Error 1
I hope I am doing something simple and stupid... it wouldn't be the
first time!
Many thanks,
Chuck