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"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type CharsetFunc func(charset string, input io.Reader) (io.Reader, error)
|
||||||
|
|
||||||
// represents a single XML document.
|
// represents a single XML document.
|
||||||
type Document struct {
|
type Document struct {
|
||||||
Version string // XML version
|
Version string // XML version
|
||||||
|
@ -45,6 +47,7 @@ type Document struct {
|
||||||
SaveDocType bool // Whether not to include the XML doctype in saves.
|
SaveDocType bool // Whether not to include the XML doctype in saves.
|
||||||
Root *Node // The document's root node.
|
Root *Node // The document's root node.
|
||||||
Entity map[string]string // Mapping of custom entity conversions.
|
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.
|
Verbose bool // [depracated] Not actually used anymore.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -56,6 +59,7 @@ func New() *Document {
|
||||||
StandAlone: "yes",
|
StandAlone: "yes",
|
||||||
SaveDocType: true,
|
SaveDocType: true,
|
||||||
Entity: make(map[string]string),
|
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) {
|
func (this *Document) LoadStream(r io.Reader) (err error) {
|
||||||
xp := xml.NewDecoder(r)
|
xp := xml.NewDecoder(r)
|
||||||
xp.Entity = this.Entity
|
xp.Entity = this.Entity
|
||||||
//xp.CharsetReader = func(enc string, input io.Reader) (io.Reader, error) {
|
xp.CharsetReader = this.CharsetReader
|
||||||
// return charset.NewReader(enc, input)
|
|
||||||
//}
|
|
||||||
|
|
||||||
this.Root = NewNode(NT_ROOT)
|
this.Root = NewNode(NT_ROOT)
|
||||||
ct := this.Root
|
ct := this.Root
|
||||||
|
|
Loading…
Reference in New Issue