本文整理匯總了Golang中encoding/xml.Decoder.Strict方法的典型用法代碼示例。如果您正苦於以下問題:Golang Decoder.Strict方法的具體用法?Golang Decoder.Strict怎麽用?Golang Decoder.Strict使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類encoding/xml.Decoder
的用法示例。
在下文中一共展示了Decoder.Strict方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: useCustomDecoder
// useCustomDecoder copy over public attributes from customDecoder
func useCustomDecoder(d *xml.Decoder) {
d.Strict = CustomDecoder.Strict
d.AutoClose = CustomDecoder.AutoClose
d.Entity = CustomDecoder.Entity
d.CharsetReader = CustomDecoder.CharsetReader
d.DefaultSpace = CustomDecoder.DefaultSpace
}
示例2: ExtractLinks
func (p *HtmlParser) ExtractLinks() []*url.URL {
var d *xml.Decoder
if reply, err := http.Get(p.url.String()); err != nil {
return nil
} else {
defer reply.Body.Close()
d = xml.NewDecoder(reply.Body)
d.Strict = false
d.AutoClose = xml.HTMLAutoClose
d.Entity = xml.HTMLEntity
}
extractHref := func(aElem xml.StartElement) string {
for _, attr := range aElem.Attr {
if attr.Name.Local == "href" {
return attr.Value
}
}
return ""
}
var links = make([]*url.URL, 0, 32)
for token, err := d.Token(); err == nil; token, err = d.Token() {
if t, ok := token.(xml.StartElement); ok && t.Name.Local == "a" {
if href := extractHref(t); href != "" {
if link, err := url.Parse(href); err == nil {
link = p.url.ResolveReference(link)
link.RawQuery = ""
link.Fragment = ""
links = append(links, link)
}
}
}
}
return links
}