tree/tree.go
func FindNodeByPos(n Node, pos int) Node {
	if n.Pos() == pos {
		return n
	}

	if elem, ok := n.(Elem); ok {
		chldrn := elem.GetChildren()
		for i := 1; i < len(chldrn); i++ {
			if chldrn[i-1].Pos() <= pos && chldrn[i].Pos() > pos {
				return FindNodeByPos(chldrn[i-1], pos)
			}
		}

		if len(chldrn) > 0 {
			if chldrn[len(chldrn)-1].Pos() <= pos {
				return FindNodeByPos(chldrn[len(chldrn)-1], pos)
			}
		}

		attrs := elem.GetAttrs()
		for _, i := range attrs {
			if i.Pos() == pos {
				return i
			}
		}

		ns := BuildNS(elem)
		for _, i := range ns {
			if i.Pos() == pos {
				return i
			}
		}
	}

	return nil
}
func FindNodeByPos(n Node, pos int) Node {
	if n.Pos() == pos {
		return n
	}

	if elem, ok := n.(Elem); ok {
		chldrn := elem.GetChildren()
		for i := 1; i < len(chldrn); i++ {
			if chldrn[i-1].Pos() <= pos && chldrn[i].Pos() > pos {
				return FindNodeByPos(chldrn[i-1], pos)
			}
		}

		if len(chldrn) > 0 {
			if chldrn[len(chldrn)-1].Pos() <= pos {
				return FindNodeByPos(chldrn[len(chldrn)-1], pos)
			}
		}

		attrs := elem.GetAttrs()
		for _, i := range attrs {
			if i.Pos() == pos {
				return i
			}
		}

		ns := BuildNS(elem)
		for _, i := range ns {
			if i.Pos() == pos {
				return i
			}
		}
	}

	return nil
}
//FindNodeByPos finds a node from the given position.  Returns nil if the node
//is not found.