func (iter *NodeIterator) SetNext(el *Node) {
	if el == nil {
		return
	}
	iter.hasNext = true
	iter.next = el.Node
}
SetNext set the node for iteration to Node "el" only if its not nil.
package html
import (
	"io"
	"strings"
	"golang.org/x/net/html"
)
type NodeIterator struct {
	current  *Node
	previous *Node
	next     *html.Node
	hasNext  bool
}
func Parse(r io.Reader) (iter *NodeIterator, err error) {
	node, err := html.Parse(r)
	if err != nil {
		return nil, err
	}
	iter = &NodeIterator{
		current:  NewNode(node),
		previous: NewNode(nil),
	}
	return iter, nil
}
func (iter *NodeIterator) Next() *Node {
	if iter.hasNext {
		iter.current.Node = iter.next
		iter.next = nil
		iter.hasNext = false
		return iter.current
	}
	if iter.current.Node == nil {
		return nil
	}
	for {
		switch {
		case iter.current.FirstChild != nil &&
			iter.current.FirstChild != iter.previous.Node &&
			iter.current.LastChild != iter.previous.Node:
			iter.current.Node = iter.current.FirstChild
		case iter.current.NextSibling != nil:
			iter.current.Node = iter.current.NextSibling
		default:
			iter.previous.Node = iter.current.Node
			iter.current.Node = iter.current.Parent
		}
		if iter.current.Node == nil {
			return nil
		}
		if iter.current.Type != html.TextNode {
			break
		}
		text := strings.TrimSpace(iter.current.Data)
		if len(text) != 0 {
			break
		}
	}
	return iter.current
}