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