编辑代码

package main
import "fmt"

func forEachNode( n *html.Node , pre, post func( n *html.Node)){
    if pre != nil{
        pre(n)
    }
    for c := n.FirstChild ; C != nil ; c = c.NetSibling{
        forEachNode(c,pre,post)
    }
    if pos != nil{
        post(n)
    }
}

var depth int

func startElement( n *html.Node ){
    if n.Type == html.ElementNode{
        fmt.Printf("%*s < %s>\n",depth * 2, "",n.Data)
        depth++
    }
}

func endElement( n *html.Node ){
    if n.Type == html.ElementNode{
        depth--
        fmt.Printf("%*s<%s>\n",depth*2,"",n.Data)
    }
}

strings.Map( func( r rune ) rune { return r + 1 }, "HAL-9000" )

func main () {
	
}