Commit c243b852 authored by Paul Warren's avatar Paul Warren
Browse files

Ensure that namespace attribute ordering is stable.

Switched from using a map to a slice to maintain the list of xmlns
attributes required on the current element.
parent 819a5d9e
......@@ -131,7 +131,7 @@ type Encoder struct {
// NewEncoder returns a new encoder that writes to w.
func NewEncoder(w io.Writer) *Encoder {
e := &Encoder{printer{Writer: bufio.NewWriter(w), prefixes: []map[string]string{make(map[string]string)}}}
e := &Encoder{printer{Writer: bufio.NewWriter(w), prefixes: [][]string{{}}}}
e.p.encoder = e
return e
}
......@@ -311,9 +311,9 @@ type printer struct {
depth int
indentedIn bool
putNewline bool
attrNS map[string]string // map prefix -> name space
attrPrefix map[string]string // map name space -> prefix
prefixes []map[string]string // stack of prefixes declared on each element
attrNS map[string]string // map prefix -> name space
attrPrefix map[string]string // map name space -> prefix
prefixes [][]string // stack of prefixes declared on each element
tags []Name
xmlDeclaration bool
}
......@@ -394,9 +394,6 @@ func (p *printer) getPrefix(url string) string {
}
}
/*
*/
p.addPrefix(prefix, url)
return prefix
......@@ -414,13 +411,13 @@ func (p *printer) addPrefix(prefix, namespace string) {
p.attrNS = make(map[string]string)
}
p.prefixes[len(p.prefixes)-1][prefix] = namespace
p.prefixes[len(p.prefixes)-1] = append(p.prefixes[len(p.prefixes)-1], prefix)
p.attrNS[prefix] = namespace
p.attrPrefix[namespace] = prefix
}
func (p *printer) markPrefix() {
p.prefixes = append(p.prefixes, make(map[string]string))
p.prefixes = append(p.prefixes, []string{})
}
// Pop the list of NS declarations on an element, and delete them from the list
......@@ -428,7 +425,7 @@ func (p *printer) markPrefix() {
func (p *printer) popPrefix() {
prefixes := p.prefixes[len(p.prefixes)-1]
p.prefixes = p.prefixes[:len(p.prefixes)-1]
for prefix, _ := range prefixes {
for _, prefix := range prefixes {
p.deleteAttrPrefix(prefix)
}
}
......@@ -733,11 +730,11 @@ func (p *printer) writeStart(start *StartElement) error {
}
/* Output any new namespace declarations that are required */
for prefix, ns := range p.prefixes[len(p.prefixes)-1] {
for _, prefix := range p.prefixes[len(p.prefixes)-1] {
p.WriteString(` xmlns:`)
p.WriteString(prefix)
p.WriteString(`="`)
EscapeText(p, []byte(ns))
EscapeText(p, []byte(p.attrNS[prefix]))
p.WriteString(`"`)
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment