File: document.go

package info (click to toggle)
golang-github-masterzen-simplexml 0.0~git20160608.0.4572e39-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 80 kB
  • ctags: 31
  • sloc: makefile: 2
file content (35 lines) | stat: -rw-r--r-- 586 bytes parent folder | download | duplicates (2)
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())
}