Closed marcelloh closed 5 years ago
Its looks a html package cause this problem.
The following section from https://godoc.org/golang.org/x/net/html#Render
Calling Parse on arbitrary input typically results in a 'well-formed' parse tree. However, it is possible for Parse to yield a 'badly-formed' parse tree. For example, in a 'well-formed' parse tree, no <a> element is a child of another <a> element: parsing "<a><a>" results in two sibling elements. Similarly, in a 'well-formed' parse tree, no <a> element is a child of a <table> element: parsing "<p><table><a>" results in a <p> with two sibling children; the <a> is reparented to the <table>'s parent. However, calling Parse on "<a><table><a>" does not return an error, but the result has an <a> element with an <a> child, and is therefore not 'well-formed'....
I written a test code to output whole HTML tree.
func main() {
s := `<html><head></head><body><td>check</td></body></html>`
node, _ := html.Parse(strings.NewReader(s))
html.Render(os.Stdout, node)
}
output: <html><head></head><body>check</body></html>
Wow, this is really a disappointment. If only the HTML is valid, it will render just fine? Based on the fact that evry html line is created by a human, and human can make mistakes, this is a sad thing.
I also read this: However, it is possible for Parse to yield a 'badly-formed' parse tree. How could I achieve this?
I guess you need implement your HTML parser. 😄
haha, yep... Perhaps I will ;-)
oh, shit. i hate the html.Render. the Strange result is possible for me to produce many bugs. libxml2 is also possible to produce many bugs by call the lib of c . the xpath of golang is very bad to use !
I have a strange result when checking some stuff, and I was able to reproduce it
test is now:
Why are the td-tags missing here?