本文整理匯總了Golang中github.com/moovweb/gokogiri/xml.Node.Attr方法的典型用法代碼示例。如果您正苦於以下問題:Golang Node.Attr方法的具體用法?Golang Node.Attr怎麽用?Golang Node.Attr使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/moovweb/gokogiri/xml.Node
的用法示例。
在下文中一共展示了Node.Attr方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: GetAsset
func (s *Scenario) GetAsset(w *Worker, base *url.URL, node xml.Node, attr string) error {
path, err := url.Parse(node.Attr(attr))
if err != nil {
return w.Fail(nil, err)
}
requestURI := base.ResolveReference(path)
req, res, err := w.SimpleGet(requestURI.String())
if err != nil {
return w.Fail(req, err)
}
if res.StatusCode != 200 {
return w.Fail(res.Request, fmt.Errorf("Response code should be %d, got %d", 200, res.StatusCode))
}
md5sum := calcMD5(res.Body)
defer res.Body.Close()
if expectedMD5, ok := s.ExpectedAssets[requestURI.RequestURI()]; ok {
if md5sum == expectedMD5 {
w.Success(StaticFileScore)
} else {
return w.Fail(res.Request, fmt.Errorf("Expected MD5 checksum is miss match %s, got %s", expectedMD5, md5sum))
}
}
return nil
}
示例2: parseAppDiv
// parseAppDiv extracts timestamp and blockindex from an appointment div
func parseAppDiv(div xml.Node) (timestamp int64, blockIndex string, err error) {
idValues := idBlockPattern.FindStringSubmatch(div.Attr("id"))
timestamp, err = strconv.ParseInt(idValues[1], 10, 64)
if err != nil {
return
}
blockIndexValues := blockIndexPattern.FindStringSubmatch(div.Content())
if len(blockIndexValues) == 1 {
blockIndex = blockIndexValues[0]
}
return
}
示例3: processNode
func processNode(node xml.Node, row string) {
row = row + node.Attr("TEXT") + "|"
kids, err := node.Search("node")
if err != nil {
log.Println("Error searching for node:", err)
return
}
if len(kids) > 0 { // has children, not a leaf node
for i := range kids {
processNode(kids[i], row)
}
} else {
fmt.Println(row) // print leaf node
}
}
示例4: parseListApp
func parseListApp(div xml.Node) (*Appointment, error) {
values := idListPattern.FindStringSubmatch(div.Attr("id"))
timestamp, err := strconv.ParseInt(values[1], 10, 64)
if err != nil {
return nil, err
}
practitioner, err := strconv.ParseInt(values[2], 10, 64)
if err != nil {
return nil, err
}
return &Appointment{
session: nil,
Timestamp: time.Unix(timestamp, 0),
Practitioner: Practitioner(practitioner),
Status: Booked,
}, nil
}
示例5: handleNode
// Formats the content of inline elements and writes the content of block
// elements to the buffer.
func (self *Formatter) handleNode(node xml.Node) {
name := node.Name()
switch {
case ignore[name]:
// Remove ignored elements.
node.SetContent("")
case name == "pre":
// Treat pre elements as code blocks.
self.writeCodeBlock(node)
case heading[name]:
// Headings are prefixed with "# ".
self.writeBlock(node, "# ")
case name == "li":
// List items are prefixed with "- ".
self.writeBlock(node, "- ")
case name == "br":
// Preserve explicit line breaks.
node.SetContent("\n")
case italic[name]:
// Wrap italic elements with /.
node.SetContent("/" + node.Content() + "/")
case bold[name]:
// Wrap bold elements with *.
node.SetContent("*" + node.Content() + "*")
case name == "img":
// Collect the src of images and replace them with (alt)[url index]
alt, src := node.Attr("alt"), node.Attr("src")
if len(alt) > 0 && len(src) > 0 {
node.SetContent(fmt.Sprintf("(%s)[%d]", alt, len(self.links)))
self.links = append(self.links, src)
}
case name == "a":
// Collect the href and and the url index.
href, content := node.Attr("href"), node.Content()
if len(href) > 0 && len(content) > 0 {
node.SetContent(fmt.Sprintf("%s[%d]", content, len(self.links)))
self.links = append(self.links, href)
}
case block[name]:
// Write the content of block elements to the buffer.
self.writeBlock(node, "")
}
}