tree/xmltree/xmlele/xmlele.go
func (x *XMLEle) CreateNode(opts *xmlbuilder.BuilderOpts) xmlbuilder.XMLBuilder {
	if opts.NodeType == tree.NtElem {
		ele := &XMLEle{
			StartElement: opts.Tok.(xml.StartElement),
			NSBuilder:    tree.NSBuilder{NS: opts.NS},
			Attrs:        make([]tree.Node, len(opts.Attrs)),
			Parent:       x,
			NodePos:      tree.NodePos(opts.NodePos),
			NodeType:     opts.NodeType,
		}
		for i := range opts.Attrs {
			ele.Attrs[i] = xmlnode.XMLNode{
				Token:    opts.Attrs[i],
				NodePos:  tree.NodePos(opts.AttrStartPos + i),
				NodeType: tree.NtAttr,
				Parent:   ele,
			}
		}
		x.Children = append(x.Children, ele)
		return ele
	}

	node := xmlnode.XMLNode{
		Token:    opts.Tok,
		NodePos:  tree.NodePos(opts.NodePos),
		NodeType: opts.NodeType,
		Parent:   x,
	}
	x.Children = append(x.Children, node)
	return x
}
func (x *XMLEle) CreateNode(opts *xmlbuilder.BuilderOpts) xmlbuilder.XMLBuilder {
	if opts.NodeType == tree.NtElem {
		ele := &XMLEle{
			StartElement: opts.Tok.(xml.StartElement),
			NSBuilder:    tree.NSBuilder{NS: opts.NS},
			Attrs:        make([]tree.Node, len(opts.Attrs)),
			Parent:       x,
			NodePos:      tree.NodePos(opts.NodePos),
			NodeType:     opts.NodeType,
		}
		for i := range opts.Attrs {
			ele.Attrs[i] = xmlnode.XMLNode{
				Token:    opts.Attrs[i],
				NodePos:  tree.NodePos(opts.AttrStartPos + i),
				NodeType: tree.NtAttr,
				Parent:   ele,
			}
		}
		x.Children = append(x.Children, ele)
		return ele
	}

	node := xmlnode.XMLNode{
		Token:    opts.Tok,
		NodePos:  tree.NodePos(opts.NodePos),
		NodeType: opts.NodeType,
		Parent:   x,
	}
	x.Children = append(x.Children, node)
	return x
}
//CreateNode is an implementation of xmlbuilder.XMLBuilder.  It appends the node
//specified in opts and returns the child if it is an element.  Otherwise, it returns x.