You can try some xpath based parser like htmlquery
s := `<html><head></head><body><h2>Relative URLs</h2>
<p><a href="html_images.asp">HTML Images</a></p></body></html>`
doc, _ := htmlquery.Parse(strings.NewReader(s))
fmt.Printf("Before update \n%s\n", htmlquery.OutputHTML(doc, true))
nodes := htmlquery.Find(doc, "/html/body//*")
for _, node := range nodes {
if node.FirstChild.DataAtom == 0 {
// DataAtom is the atom for Data, or zero if Data is not a known tag name.
node.FirstChild.Data = strings.ToUpper(node.FirstChild.Data)
}
}
fmt.Printf("After update \n%s\n", htmlquery.OutputHTML(doc, true))
Output
Before update
<html><head></head><body><h2>Relative URLs</h2>
<p><a href="html_images.asp">HTML Images</a></p></body></html>
After update
<html><head></head><body><h2>RELATIVE URLS</h2>
<p><a href="html_images.asp">HTML IMAGES</a></p></body></html>
golang.org/x/net/html.