1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
|
package dom
import (
"bytes"
"fmt"
)
type Document struct {
root *Element
PrettyPrint bool
Indentation string
DocType bool
}
func CreateDocument() *Document {
return &Document{ PrettyPrint: false, Indentation: " ", DocType: true }
}
func (doc *Document) SetRoot(node *Element) {
node.parent = nil
doc.root = node
}
func (doc *Document) String() string {
var b bytes.Buffer
if doc.DocType {
fmt.Fprintln(&b, `<?xml version="1.0" encoding="utf-8" ?>`)
}
if doc.root != nil {
doc.root.Bytes(&b, doc.PrettyPrint, doc.Indentation, 0)
}
return string(b.Bytes())
}
|