Add CharsetReader function pointer to Document struct as a public field. This allows the caller to specify their own charset conversion handler when loading xml content.
This commit is contained in:
parent
b14dd79d8d
commit
fcfc98fd64
|
@ -37,6 +37,8 @@ import (
|
|||
"strings"
|
||||
)
|
||||
|
||||
type CharsetFunc func(charset string, input io.Reader) (io.Reader, error)
|
||||
|
||||
// represents a single XML document.
|
||||
type Document struct {
|
||||
Version string // XML version
|
||||
|
@ -45,6 +47,7 @@ type Document struct {
|
|||
SaveDocType bool // Whether not to include the XML doctype in saves.
|
||||
Root *Node // The document's root node.
|
||||
Entity map[string]string // Mapping of custom entity conversions.
|
||||
CharsetReader CharsetFunc // Override the xml decoder's CharsetReader. Defaults to nil.
|
||||
Verbose bool // [depracated] Not actually used anymore.
|
||||
}
|
||||
|
||||
|
@ -56,6 +59,7 @@ func New() *Document {
|
|||
StandAlone: "yes",
|
||||
SaveDocType: true,
|
||||
Entity: make(map[string]string),
|
||||
CharsetReader: nil,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -82,9 +86,7 @@ func (this *Document) SelectNodes(namespace, name string) []*Node {
|
|||
func (this *Document) LoadStream(r io.Reader) (err error) {
|
||||
xp := xml.NewDecoder(r)
|
||||
xp.Entity = this.Entity
|
||||
//xp.CharsetReader = func(enc string, input io.Reader) (io.Reader, error) {
|
||||
// return charset.NewReader(enc, input)
|
||||
//}
|
||||
xp.CharsetReader = this.CharsetReader
|
||||
|
||||
this.Root = NewNode(NT_ROOT)
|
||||
ct := this.Root
|
||||
|
|
Loading…
Reference in New Issue