当前位置: 首页>>代码示例>>Golang>>正文


Golang Node.SelectNodes方法代码示例

本文整理汇总了Golang中github.com/jteeuwen/go-pkg-xmlx.Node.SelectNodes方法的典型用法代码示例。如果您正苦于以下问题:Golang Node.SelectNodes方法的具体用法?Golang Node.SelectNodes怎么用?Golang Node.SelectNodes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/jteeuwen/go-pkg-xmlx.Node的用法示例。


在下文中一共展示了Node.SelectNodes方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: readAtomChannel

func readAtomChannel(ns string, node *xmlx.Node) *Channel {
	ch := &Channel{
		Title:         node.S(ns, "title"),
		LastBuildDate: node.S(ns, "updated"),
		Id:            node.S(ns, "id"),
		Rights:        node.S(ns, "rights"),
	}

	for _, v := range node.SelectNodesDirect(ns, "link") {
		ch.Links = append(ch.Links, Link{
			Href:     v.As("", "href"),
			Rel:      v.As("", "rel"),
			Type:     v.As("", "type"),
			HrefLang: v.As("", "hreflang"),
		})
	}

	if tn := node.SelectNode(ns, "subtitle"); tn != nil {
		ch.SubTitle = SubTitle{
			Type: tn.As("", "type"),
			Text: tn.GetValue(),
		}
	}

	if tn := node.SelectNode(ns, "generator"); tn != nil {
		ch.Generator = Generator{
			Uri:     tn.As("", "uri"),
			Version: tn.As("", "version"),
			Text:    tn.GetValue(),
		}
	}

	if tn := node.SelectNode(ns, "author"); tn != nil {
		ch.Author = Author{
			Name:  tn.S("", "name"),
			Uri:   tn.S("", "uri"),
			Email: tn.S("", "email"),
		}
	}

	for _, item := range node.SelectNodes(ns, "entry") {
		ch.Items = append(ch.Items, readAtomItem(ns, item))
	}

	return ch
}
开发者ID:hawx,项目名称:riviera,代码行数:46,代码来源:atom.go

示例2: readAtomItem

func readAtomItem(ns string, item *xmlx.Node) *Item {
	i := &Item{
		Title:       item.S(ns, "title"),
		Id:          item.S(ns, "id"),
		PubDate:     item.S(ns, "updated"),
		Description: item.S(ns, "summary"),
	}

	for _, v := range item.SelectNodes(ns, "link") {
		if v.As(ns, "rel") == "enclosure" {
			i.Enclosures = append(i.Enclosures, Enclosure{
				Url:  v.As("", "href"),
				Type: v.As("", "type"),
			})
		} else {
			i.Links = append(i.Links, Link{
				Href:     v.As("", "href"),
				Rel:      v.As("", "rel"),
				Type:     v.As("", "type"),
				HrefLang: v.As("", "hreflang"),
			})
		}
	}

	for _, v := range item.SelectNodes(ns, "contributor") {
		i.Contributors = append(i.Contributors, v.S("", "name"))
	}

	for _, cv := range item.SelectNodes(ns, "category") {
		i.Categories = append(i.Categories, Category{
			Domain: "",
			Text:   cv.As("", "term"),
		})
	}

	if tn := item.SelectNode(ns, "content"); tn != nil {
		i.Content = &Content{
			Type: tn.As("", "type"),
			Lang: tn.S("xml", "lang"),
			Base: tn.S("xml", "base"),
			Text: tn.GetValue(),
		}
	}

	if tn := item.SelectNode(ns, "author"); tn != nil {
		i.Author = Author{
			Name:  tn.S(ns, "name"),
			Uri:   tn.S(ns, "uri"),
			Email: tn.S(ns, "email"),
		}
	}

	return i
}
开发者ID:hawx,项目名称:riviera,代码行数:54,代码来源:atom.go

示例3: readRssChannel

func readRssChannel(ns string, doc *xmlx.Document, node *xmlx.Node) *Channel {
	ch := &Channel{
		Title:          node.S(ns, "title"),
		Description:    node.S(ns, "description"),
		Language:       node.S(ns, "language"),
		Copyright:      node.S(ns, "copyright"),
		ManagingEditor: node.S(ns, "managingEditor"),
		WebMaster:      node.S(ns, "webMaster"),
		PubDate:        node.S(ns, "pubDate"),
		LastBuildDate:  node.S(ns, "lastBuildDate"),
		Docs:           node.S(ns, "docs"),
		TTL:            node.I(ns, "ttl"),
		Rating:         node.S(ns, "rating"),
	}

	for _, v := range node.SelectNodes(ns, "link") {
		lnk := Link{}
		if v.Name.Space == "http://www.w3.org/2005/Atom" && v.Name.Local == "link" {
			lnk.Href = v.As("", "href")
			lnk.Rel = v.As("", "rel")
			lnk.Type = v.As("", "type")
			lnk.HrefLang = v.As("", "hreflang")
		} else {
			lnk.Href = v.GetValue()
		}

		ch.Links = append(ch.Links, lnk)
	}

	for _, v := range node.SelectNodes(ns, "category") {
		ch.Categories = append(ch.Categories, Category{
			Domain: v.As(ns, "domain"),
			Text:   v.GetValue(),
		})
	}

	if n := node.SelectNode(ns, "generator"); n != nil {
		ch.Generator = Generator{
			Text: n.GetValue(),
		}
	}

	for _, v := range node.SelectNodes(ns, "hour") {
		ch.SkipHours = append(ch.SkipHours, v.I(ns, "hour"))
	}

	for _, v := range node.SelectNodes(ns, "days") {
		ch.SkipDays = append(ch.SkipDays, days[v.GetValue()])
	}

	if n := node.SelectNode(ns, "image"); n != nil {
		ch.Image = Image{
			Title:       n.S(ns, "title"),
			Url:         n.S(ns, "url"),
			Link:        n.S(ns, "link"),
			Width:       n.I(ns, "width"),
			Height:      n.I(ns, "height"),
			Description: n.S(ns, "description"),
		}
	}

	if n := node.SelectNode(ns, "cloud"); n != nil {
		ch.Cloud = Cloud{
			Domain:            n.As(ns, "domain"),
			Port:              n.Ai(ns, "port"),
			Path:              n.As(ns, "path"),
			RegisterProcedure: n.As(ns, "registerProcedure"),
			Protocol:          n.As(ns, "protocol"),
		}
	}

	if n := node.SelectNode(ns, "textInput"); n != nil {
		ch.TextInput = Input{
			Title:       n.S(ns, "title"),
			Description: n.S(ns, "description"),
			Name:        n.S(ns, "name"),
			Link:        n.S(ns, "link"),
		}
	}

	list := node.SelectNodes(ns, "item")
	if len(list) == 0 {
		list = doc.SelectNodes(ns, "item")
	}

	for _, item := range list {
		ch.Items = append(ch.Items, readRssItem(ns, item))
	}

	ch.Extensions = make(map[string]map[string][]Extension)
	for _, v := range node.Children {
		getExtensions(&ch.Extensions, v)
	}

	return ch
}
开发者ID:hawx,项目名称:riviera,代码行数:96,代码来源:rss.go

示例4: readRssItem

func readRssItem(ns string, item *xmlx.Node) *Item {
	i := &Item{
		Title:       item.S(ns, "title"),
		Description: item.S(ns, "description"),
		Comments:    item.S(ns, "comments"),
		PubDate:     item.S(ns, "pubDate"),
	}

	for _, v := range item.SelectNodes(ns, "link") {
		if v.Name.Space == "http://www.w3.org/2005/Atom" && v.Name.Local == "link" {
			i.Links = append(i.Links, Link{
				Href:     v.As("", "href"),
				Rel:      v.As("", "rel"),
				Type:     v.As("", "type"),
				HrefLang: v.As("", "hreflang"),
			})
		} else {
			i.Links = append(i.Links, Link{Href: v.GetValue()})
		}
	}

	if n := item.SelectNode(ns, "author"); n != nil {
		i.Author.Name = n.GetValue()

	} else if n := item.SelectNode(ns, "creator"); n != nil {
		i.Author.Name = n.GetValue()
	}

	if n := item.SelectNode(ns, "guid"); n != nil {
		i.Guid = &Guid{Guid: n.GetValue(), IsPermaLink: n.As("", "isPermalink") == "true"}
	}

	for _, lv := range item.SelectNodes(ns, "category") {
		i.Categories = append(i.Categories, Category{
			Domain: lv.As(ns, "domain"),
			Text:   lv.GetValue(),
		})
	}

	for _, lv := range item.SelectNodes(ns, "enclosure") {
		i.Enclosures = append(i.Enclosures, Enclosure{
			Url:    lv.As(ns, "url"),
			Length: lv.Ai64(ns, "length"),
			Type:   lv.As(ns, "type"),
		})
	}

	if src := item.SelectNode(ns, "source"); src != nil {
		i.Source = new(Source)
		i.Source.Url = src.As(ns, "url")
		i.Source.Text = src.GetValue()
	}

	for _, lv := range item.SelectNodes("http://purl.org/rss/1.0/modules/content/", "*") {
		if lv.Name.Local == "encoded" {
			i.Content = &Content{
				Text: lv.String(),
			}
			break
		}
	}

	i.Extensions = make(map[string]map[string][]Extension)
	for _, lv := range item.Children {
		getExtensions(&i.Extensions, lv)
	}

	return i
}
开发者ID:hawx,项目名称:riviera,代码行数:69,代码来源:rss.go


注:本文中的github.com/jteeuwen/go-pkg-xmlx.Node.SelectNodes方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。