func (x *xhtml) write(xhtmlFilePath string) {
	xhtmlFileContent, err := xml.MarshalIndent(x.xml, "", "  ")
	if err != nil {
		panic(fmt.Sprintf(
			"Error marshalling XML for XHTML file: %s\n"+
				"\tXML=%#v",
			err,
			x.xml))
	}
	xhtmlFileContent = append([]byte(xhtmlDoctype), xhtmlFileContent...)
	xhtmlFileContent = append([]byte(xml.Header), xhtmlFileContent...)
	xhtmlFileContent = append(xhtmlFileContent, "\n"...)
	if err := filesystem.WriteFile(xhtmlFilePath, []byte(xhtmlFileContent), filePermissions); err != nil {
		panic(fmt.Sprintf("Error writing XHTML file: %s", err))
	}
}
Write the XHTML file to the specified path
package epub
import (
	"encoding/xml"
	"fmt"
)
const (
	xhtmlDoctype = `<!DOCTYPE html>
`
	xhtmlLinkRel  = "stylesheet"
	xhtmlTemplate = `<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <title></title>
  </head>
  <body></body>
</html>
`
)
type xhtml struct {
	xml *xhtmlRoot
}
type xhtmlRoot struct {
	XMLName   xml.Name      `xml:"http://www.w3.org/1999/xhtml html"`
	XmlnsEpub string        `xml:"xmlns:epub,attr,omitempty"`
	Head      xhtmlHead     `xml:"head"`
	Body      xhtmlInnerxml `xml:"body"`
}
type xhtmlHead struct {
	Title string `xml:"title"`
	Link  *xhtmlLink
}
type xhtmlLink struct {
	XMLName xml.Name `xml:"link,omitempty"`
	Rel     string   `xml:"rel,attr,omitempty"`
	Type    string   `xml:"type,attr,omitempty"`
	Href    string   `xml:"href,attr,omitempty"`
}
type xhtmlInnerxml struct {
	XML string `xml:",innerxml"`
}
func newXhtml(body string) *xhtml {
	x := &xhtml{
		xml: newXhtmlRoot(),
	}
	x.setBody(body)
	return x
}
func newXhtmlRoot() *xhtmlRoot {
	r := &xhtmlRoot{}
	err := xml.Unmarshal([]byte(xhtmlTemplate), &r)
	if err != nil {
		panic(fmt.Sprintf(
			"Error unmarshalling xhtmlRoot: %s\n"+
				"\txhtmlRoot=%#v\n"+
				"\txhtmlTemplate=%s",
			err,
			*r,
			xhtmlTemplate))
	}
	return r
}
func (x *xhtml) setBody(body string) {
	x.xml.Body.XML = "\n" + body + "\n"
}
func (x *xhtml) setCSS(path string) {
	x.xml.Head.Link = &xhtmlLink{
		Rel:  xhtmlLinkRel,
		Type: mediaTypeCSS,
		Href: path,
	}
}
func (x *xhtml) setTitle(title string) {
	x.xml.Head.Title = title
}
func (x *xhtml) setXmlnsEpub(xmlns string) {
	x.xml.XmlnsEpub = xmlns
}
func (x *xhtml) Title() string {
	return x.xml.Head.Title
}