func (d *Document) ReadFromBytes(b []byte) error {
	_, err := d.ReadFrom(bytes.NewReader(b))
	return err
}
ReadFromBytes reads XML from the byte slice b into the document d.
package etree
import (
	"bufio"
	"bytes"
	"encoding/xml"
	"errors"
	"io"
	"os"
	"sort"
	"strings"
)
const (
	NoIndent = -1
)
var ErrXML = errors.New("etree: invalid XML format")
type ReadSettings struct {
	CharsetReader func(charset string, input io.Reader) (io.Reader, error)
	Permissive bool
	Entity map[string]string
}
func newReadSettings() ReadSettings {
	return ReadSettings{
		CharsetReader: func(label string, input io.Reader) (io.Reader, error) {
			return input, nil
		},
		Permissive: false,
	}
}
type WriteSettings struct {
	CanonicalEndTags bool
	CanonicalText bool
	CanonicalAttrVal bool
	UseCRLF bool
}
func newWriteSettings() WriteSettings {
	return WriteSettings{
		CanonicalEndTags: false,
		CanonicalText:    false,
		CanonicalAttrVal: false,
		UseCRLF:          false,
	}
}
type Token interface {
	Parent() *Element
	Index() int
	dup(parent *Element) Token
	setParent(parent *Element)
	setIndex(index int)
	writeTo(w *bufio.Writer, s *WriteSettings)
}
type Document struct {
	Element
	ReadSettings  ReadSettings
	WriteSettings WriteSettings
}
type Element struct {
	Space, Tag string    
	Attr       []Attr    
	Child      []Token   
	parent     *Element  
	index      int       
}
type Attr struct {
	Space, Key string    
	Value      string    
	element    *Element  
}
type charDataFlags uint8
const (
	whitespaceFlag charDataFlags = 1 << iota
	cdataFlag
)
type CharData struct {
	Data   string
	parent *Element
	index  int
	flags  charDataFlags
}
type Comment struct {
	Data   string
	parent *Element
	index  int
}
type Directive struct {
	Data   string
	parent *Element
	index  int
}
type ProcInst struct {
	Target string
	Inst   string
	parent *Element
	index  int
}
func NewDocument() *Document {
	return &Document{
		Element{Child: make([]Token, 0)},
		newReadSettings(),
		newWriteSettings(),
	}
}
func (d *Document) Copy() *Document {
	return &Document{*(d.dup(nil).(*Element)), d.ReadSettings, d.WriteSettings}
}
func (d *Document) Root() *Element {
	for _, t := range d.Child {
		if c, ok := t.(*Element); ok {
			return c
		}
	}
	return nil
}
func (d *Document) SetRoot(e *Element) {
	if e.parent != nil {
		e.parent.RemoveChild(e)
	}
	p := &d.Element
	e.setParent(p)
	for i, t := range p.Child {
		if _, ok := t.(*Element); ok {
			t.setParent(nil)
			t.setIndex(-1)
			p.Child[i] = e
			e.setIndex(i)
			return
		}
	}
	p.addChild(e)
}
func (d *Document) ReadFrom(r io.Reader) (n int64, err error) {
	return d.Element.readFrom(r, d.ReadSettings)
}
func (d *Document) ReadFromFile(filename string) error {
	f, err := os.Open(filename)
	if err != nil {
		return err
	}
	defer f.Close()
	_, err = d.ReadFrom(f)
	return err
}