1 // Copyright 2012 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
5 // This example demonstrates parsing HTML data and walking the resulting tree.
13 "golang.org/x/net/html"
17 s := `<p>Links:</p><ul><li><a href="foo">Foo</a><li><a href="/bar/baz">BarBaz</a></ul>`
18 doc, err := html.Parse(strings.NewReader(s))
22 var f func(*html.Node)
23 f = func(n *html.Node) {
24 if n.Type == html.ElementNode && n.Data == "a" {
25 for _, a := range n.Attr {
32 for c := n.FirstChild; c != nil; c = c.NextSibling {