Is there a way to extract the source of an image in an HTML file using only one struct (with encode/xml)? Now I have something like this
type XML struct {
A Image `xml:"div>img"`
}
type Image struct {
I string `xml:"src,attr"`
}
And would be great to only declare something like this :
type Image struct {
I string `xml:"div>img,src,attr"`
}
This is the HTML :
<div><div><img src="hello.png"/></div></div>
Seems that a good way is to use the
exp/htmlpackage, like this:All this
FirstChildandNextSiblingare needed becauseexp/htmlconstructs a “correct” html5 tree so this code is actually parsing this: