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


Golang Document.SelectNode方法代码示例

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


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

示例1: isAtom

func (this *Feed) isAtom(doc *xmlx.Document) bool {
	if doc.SelectNode("http://www.w3.org/2005/Atom", "feed") != nil ||
		doc.SelectNode("http://purl.org/atom/ns#", "feed") != nil {
		return true
	}
	return false
}
开发者ID:mdaisuke,项目名称:go-pkg-rss,代码行数:7,代码来源:feed.go

示例2: GetVersionInfo

// Returns the type of the feed, ie. "atom" or "rss", and the version number as an array.
// The first item in the array is the major and the second the minor version number.
func (this *Feed) GetVersionInfo(doc *xmlx.Document) (ftype string, fversion [2]int) {
	var node *xmlx.Node

	if this.isAtom(doc) {
		ftype = "atom"
		fversion = [2]int{1, 0}
		return
	}

	if this.isRss(doc) {
		ftype = "rss"
		major := 0
		minor := 0
		version := node.As("", "version")
		p := strings.Index(version, ".")
		if p != -1 {
			major, _ = strconv.Atoi(version[0:p])
			minor, _ = strconv.Atoi(version[p+1 : len(version)])
		}
		fversion = [2]int{major, minor}
		return
	}

	// issue#5: Some documents have an RDF root node instead of rss.
	if node = doc.SelectNode("http://www.w3.org/1999/02/22-rdf-syntax-ns#", "RDF"); node != nil {
		ftype = "rss"
		fversion = [2]int{1, 1}
		return
	}

	ftype = "unknown"
	fversion = [2]int{0, 0}
	return
}
开发者ID:mdaisuke,项目名称:go-pkg-rss,代码行数:36,代码来源:feed.go

示例3: parser

func parser(doc *xmlx.Document) *RssXml {
	rss := &RssXml{
		Version: "2.0",
	}
	const ns = "*"
	node := doc.SelectNode(ns, "rss")
	channel := node.SelectNode(ns, "channel")

	feed := &RssFeed{}

	feed.Title = channel.S(ns, "title")
	feed.Link = channel.S(ns, "link")
	feed.Description = channel.S(ns, "description")
	feed.Language = channel.S(ns, "language")
	feed.Copyright = channel.S(ns, "copyright")
	feed.PubDate = channel.S(ns, "pubDate")

	items := channel.SelectNodes(ns, "item")
	for _, i := range items {
		item := &RssItem{}
		item.Title = i.S(ns, "title")
		item.Link = i.S(ns, "link")
		item.Description = i.S(ns, "description")
		item.PubDate = i.S(ns, "pubDate")
		feed.items = append(feed.items, item)
	}
	rss.Channel = feed

	return rss
}
开发者ID:xeodou,项目名称:cnbeta-rss,代码行数:30,代码来源:cnbeta.go

示例4: readRss2

func readRss2(doc *xmlx.Document) (foundChannels []*Channel, err error) {
	const ns = "*"

	root := doc.SelectNode(ns, "rss")
	if root == nil {
		root = doc.SelectNode(ns, "RDF")
	}

	if root == nil {
		return foundChannels, errors.New("Failed to find rss/rdf node in XML.")
	}

	for _, node := range root.SelectNodes(ns, "channel") {
		foundChannels = append(foundChannels, readRssChannel(ns, doc, node))
	}

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

示例5: GetVersionInfo

func GetVersionInfo(doc *xmlx.Document) (string, [2]int) {
	if node := doc.SelectNode("http://www.w3.org/2005/Atom", "feed"); node != nil {
		return "atom", [2]int{1, 0}
	}

	if node := doc.SelectNode("", "rss"); node != nil {
		version := node.As("", "version")
		p := strings.Index(version, ".")
		major, _ := strconv.Atoi(version[0:p])
		minor, _ := strconv.Atoi(version[p+1 : len(version)])

		return "rss", [2]int{major, minor}
	}

	// issue#5: Some documents have an RDF root node instead of rss.
	if node := doc.SelectNode("http://www.w3.org/1999/02/22-rdf-syntax-ns#", "RDF"); node != nil {
		return "rss", [2]int{1, 1}
	}

	return "unknown", [2]int{0, 0}
}
开发者ID:hawx,项目名称:riviera,代码行数:21,代码来源:feed.go

示例6: readRss2

func (this *Feed) readRss2(doc *xmlx.Document) (err error) {
	var foundChannels []*Channel
	var ch *Channel
	var i *Item
	var n *xmlx.Node
	var list, tl []*xmlx.Node
	const ns = "*"

	root := doc.SelectNode(ns, "rss")
	if root == nil {
		root = doc.SelectNode(ns, "RDF")
	}

	if root == nil {
		return errors.New("Failed to find rss/rdf node in XML.")
	}

	channels := root.SelectNodes(ns, "channel")
	for _, node := range channels {
		ch = new(Channel)
		foundChannels = append(foundChannels, ch)

		ch.Title = node.S(ns, "title")
		list = node.SelectNodes(ns, "link")
		ch.Links = make([]Link, len(list))

		for i, v := range list {
			if v.Name.Space == "http://www.w3.org/2005/Atom" && v.Name.Local == "link" {
				ch.Links[i].Href = v.As("", "href")
				ch.Links[i].Rel = v.As("", "rel")
				ch.Links[i].Type = v.As("", "type")
				ch.Links[i].HrefLang = v.As("", "hreflang")
			} else {
				ch.Links[i].Href = v.GetValue()
			}
		}

		ch.Description = node.S(ns, "description")
		ch.Language = node.S(ns, "language")
		ch.Copyright = node.S(ns, "copyright")
		ch.ManagingEditor = node.S(ns, "managingEditor")
		ch.WebMaster = node.S(ns, "webMaster")
		ch.PubDate = node.S(ns, "pubDate")
		ch.LastBuildDate = node.S(ns, "lastBuildDate")
		ch.Docs = node.S(ns, "docs")

		list = node.SelectNodes(ns, "category")
		ch.Categories = make([]*Category, len(list))
		for i, v := range list {
			ch.Categories[i] = new(Category)
			ch.Categories[i].Domain = v.As(ns, "domain")
			ch.Categories[i].Text = v.GetValue()
		}

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

		ch.TTL = node.I(ns, "ttl")
		ch.Rating = node.S(ns, "rating")

		list = node.SelectNodes(ns, "hour")
		ch.SkipHours = make([]int, len(list))
		for i, v := range list {
			ch.SkipHours[i] = v.I(ns, "hour")
		}

		list = node.SelectNodes(ns, "days")
		ch.SkipDays = make([]int, len(list))
		for i, v := range list {
			ch.SkipDays[i] = days[v.GetValue()]
		}

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

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

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

//.........这里部分代码省略.........
开发者ID:ronaldfoize,项目名称:go-pkg-rss,代码行数:101,代码来源:rss.go

示例7: readRss2

func (this *Feed) readRss2(doc *xmlx.Document) (err error) {
	days := make(map[string]int)
	days["Monday"] = 1
	days["Tuesday"] = 2
	days["Wednesday"] = 3
	days["Thursday"] = 4
	days["Friday"] = 5
	days["Saturday"] = 6
	days["Sunday"] = 7

	getChan := func(pubdate, title string) *Channel {
		for _, c := range this.Channels {
			switch {
			case len(pubdate) > 0:
				if c.PubDate == pubdate {
					return c
				}
			case len(title) > 0:
				if c.Title == title {
					return c
				}
			}
		}
		return nil
	}

	var ch *Channel
	var i *Item
	var n *xmlx.Node
	var list, tl []*xmlx.Node
	const ns = "*"

	root := doc.SelectNode(ns, "rss")
	if root == nil {
		root = doc.SelectNode(ns, "RDF")
	}

	if root == nil {
		return errors.New("Failed to find rss/rdf node in XML.")
	}

	channels := root.SelectNodes(ns, "channel")
	for _, node := range channels {
		if ch = getChan(node.S(ns, "pubDate"), node.S(ns, "title")); ch == nil {
			ch = new(Channel)
			this.Channels = append(this.Channels, ch)
		}

		ch.Title = node.S(ns, "title")
		list = node.SelectNodes(ns, "link")
		ch.Links = make([]Link, len(list))

		for i, v := range list {
			ch.Links[i].Href = v.GetValue()
		}

		ch.Description = node.S(ns, "description")
		ch.Language = node.S(ns, "language")
		ch.Copyright = node.S(ns, "copyright")
		ch.ManagingEditor = node.S(ns, "managingEditor")
		ch.WebMaster = node.S(ns, "webMaster")
		ch.PubDate = node.S(ns, "pubDate")
		ch.LastBuildDate = node.S(ns, "lastBuildDate")
		ch.Docs = node.S(ns, "docs")

		list = node.SelectNodes(ns, "category")
		ch.Categories = make([]*Category, len(list))
		for i, v := range list {
			ch.Categories[i] = new(Category)
			ch.Categories[i].Domain = v.As(ns, "domain")
			ch.Categories[i].Text = v.GetValue()
		}

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

		ch.TTL = node.I(ns, "ttl")
		ch.Rating = node.S(ns, "rating")

		list = node.SelectNodes(ns, "hour")
		ch.SkipHours = make([]int, len(list))
		for i, v := range list {
			ch.SkipHours[i] = v.I(ns, "hour")
		}

		list = node.SelectNodes(ns, "days")
		ch.SkipDays = make([]int, len(list))
		for i, v := range list {
			ch.SkipDays[i] = days[v.GetValue()]
		}

		if n = node.SelectNode(ns, "image"); n != nil {
			ch.Image.Title = n.S(ns, "title")
			ch.Image.Url = n.S(ns, "url")
			ch.Image.Link = n.S(ns, "link")
			ch.Image.Width = n.I(ns, "width")
			ch.Image.Height = n.I(ns, "height")
			ch.Image.Description = n.S(ns, "description")
//.........这里部分代码省略.........
开发者ID:ChimeraCoder,项目名称:go-pkg-rss,代码行数:101,代码来源:rss.go

示例8: isRss

func (this *Feed) isRss(doc *xmlx.Document) bool {
	if doc.SelectNode("", "rss") != nil {
		return true
	}
	return false
}
开发者ID:mdaisuke,项目名称:go-pkg-rss,代码行数:6,代码来源:feed.go


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