本文整理汇总了Golang中github.com/jteeuwen/go-pkg-xmlx.Node.GetValue方法的典型用法代码示例。如果您正苦于以下问题:Golang Node.GetValue方法的具体用法?Golang Node.GetValue怎么用?Golang Node.GetValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/jteeuwen/go-pkg-xmlx.Node
的用法示例。
在下文中一共展示了Node.GetValue方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: getExtension
func getExtension(node *xmlx.Node) (Extension, bool) {
var extension Extension
if node.Name.Space != "" {
extension = Extension{Name: node.Name.Local, Value: node.GetValue()}
extension.Attrs = make(map[string]string)
extension.Childrens = make(map[string][]Extension, 0)
for _, x := range node.Attributes {
extension.Attrs[x.Name.Local] = x.Value
}
for _, y := range node.Children {
children, ok := getExtension(y)
if ok {
extension.Childrens[y.Name.Local] = append(extension.Childrens[y.Name.Local], children)
}
}
return extension, true
} else {
return extension, false
}
}
示例2: getExtension
func getExtension(node *xmlx.Node) (extension Extension, ok bool) {
if node.Name.Space == "" {
return extension, false
}
extension = Extension{
Name: node.Name.Local,
Value: node.GetValue(),
Attrs: make(map[string]string),
Childrens: make(map[string][]Extension, 0),
}
for _, attr := range node.Attributes {
extension.Attrs[attr.Name.Local] = attr.Value
}
for _, child := range node.Children {
if ext, ok := getExtension(child); ok {
extension.Childrens[child.Name.Local] = append(extension.Childrens[child.Name.Local], ext)
}
}
return extension, true
}
示例3: 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")
}
//.........这里部分代码省略.........
示例4: readAtom
func (this *Feed) readAtom(doc *xmlx.Document) (err error) {
ns := "http://www.w3.org/2005/Atom"
channels := doc.SelectNodes(ns, "feed")
var foundChannels []*Channel
var ch *Channel
var i *Item
var tn *xmlx.Node
var list []*xmlx.Node
for _, node := range channels {
ch = new(Channel)
foundChannels = append(foundChannels, ch)
ch.Title = node.S(ns, "title")
ch.LastBuildDate = node.S(ns, "updated")
ch.Id = node.S(ns, "id")
ch.Rights = node.S(ns, "rights")
list = node.SelectNodes(ns, "link")
ch.Links = make([]Link, len(list))
for i, v := range list {
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")
}
if tn = node.SelectNode(ns, "subtitle"); tn != nil {
ch.SubTitle = SubTitle{}
ch.SubTitle.Type = tn.As("", "type")
ch.SubTitle.Text = tn.GetValue()
}
if tn = node.SelectNode(ns, "generator"); tn != nil {
ch.Generator = Generator{}
ch.Generator.Uri = tn.As("", "uri")
ch.Generator.Version = tn.As("", "version")
ch.Generator.Text = tn.GetValue()
}
if tn = node.SelectNode(ns, "author"); tn != nil {
ch.Author = Author{}
ch.Author.Name = tn.S("", "name")
ch.Author.Uri = tn.S("", "uri")
ch.Author.Email = tn.S("", "email")
}
list = node.SelectNodes(ns, "entry")
for _, item := range list {
i = new(Item)
i.Title = item.S(ns, "title")
i.Id = item.S(ns, "id")
i.PubDate = item.S(ns, "updated")
i.Description = item.S(ns, "summary")
links := item.SelectNodes(ns, "link")
for _, lv := range links {
if lv.As(ns, "rel") == "enclosure" {
enc := new(Enclosure)
enc.Url = lv.As("", "href")
enc.Type = lv.As("", "type")
i.Enclosures = append(i.Enclosures, enc)
} else {
lnk := new(Link)
lnk.Href = lv.As("", "href")
lnk.Rel = lv.As("", "rel")
lnk.Type = lv.As("", "type")
lnk.HrefLang = lv.As("", "hreflang")
i.Links = append(i.Links, lnk)
}
}
list = item.SelectNodes(ns, "contributor")
for _, cv := range list {
i.Contributors = append(i.Contributors, cv.S("", "name"))
}
list = item.SelectNodes(ns, "category")
for _, cv := range list {
cat := new(Category)
cat.Domain = ""
cat.Text = cv.As("", "term")
i.Categories = append(i.Categories, cat)
}
if tn = item.SelectNode(ns, "content"); tn != nil {
i.Content = new(Content)
i.Content.Type = tn.As("", "type")
i.Content.Lang = tn.S("xml", "lang")
i.Content.Base = tn.S("xml", "base")
i.Content.Text = tn.GetValue()
}
if tn = item.SelectNode(ns, "author"); tn != nil {
i.Author = Author{}
i.Author.Name = tn.S(ns, "name")
i.Author.Uri = tn.S(ns, "uri")
i.Author.Email = tn.S(ns, "email")
//.........这里部分代码省略.........
示例5: 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")
//.........这里部分代码省略.........
示例6: readAtom
func (this *Feed) readAtom(doc *xmlx.Document) (err error) {
ns := "http://www.w3.org/2005/Atom"
channels := doc.SelectNodes(ns, "feed")
getChan := func(id, title string) *Channel {
for _, c := range this.Channels {
switch {
case len(id) > 0:
if c.Id == id {
return c
}
case len(title) > 0:
if c.Title == title {
return c
}
}
}
return nil
}
var ch *Channel
var i *Item
var tn *xmlx.Node
var list []*xmlx.Node
for _, node := range channels {
if ch = getChan(node.S(ns, "id"), node.S(ns, "title")); ch == nil {
ch = new(Channel)
this.Channels = append(this.Channels, ch)
}
ch.Title = node.S(ns, "title")
ch.LastBuildDate = node.S(ns, "updated")
ch.Id = node.S(ns, "id")
ch.Rights = node.S(ns, "rights")
list = node.SelectNodes(ns, "link")
ch.Links = make([]Link, len(list))
for i, v := range list {
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")
}
if tn = node.SelectNode(ns, "subtitle"); tn != nil {
ch.SubTitle = SubTitle{}
ch.SubTitle.Type = tn.As("", "type")
ch.SubTitle.Text = tn.GetValue()
}
if tn = node.SelectNode(ns, "generator"); tn != nil {
ch.Generator = Generator{}
ch.Generator.Uri = tn.As("", "uri")
ch.Generator.Version = tn.As("", "version")
ch.Generator.Text = tn.GetValue()
}
if tn = node.SelectNode(ns, "author"); tn != nil {
ch.Author = Author{}
ch.Author.Name = tn.S("", "name")
ch.Author.Uri = tn.S("", "uri")
ch.Author.Email = tn.S("", "email")
}
itemcount := len(ch.Items)
list = node.SelectNodes(ns, "entry")
for _, item := range list {
i = new(Item)
i.Title = item.S(ns, "title")
i.Id = item.S(ns, "id")
i.PubDate = item.S(ns, "updated")
i.Description = item.S(ns, "summary")
links := item.SelectNodes(ns, "link")
for _, lv := range links {
if lv.As(ns, "rel") == "enclosure" {
enc := new(Enclosure)
enc.Url = lv.As("", "href")
enc.Type = lv.As("", "type")
i.Enclosures = append(i.Enclosures, enc)
} else {
lnk := new(Link)
lnk.Href = lv.As("", "href")
lnk.Rel = lv.As("", "rel")
lnk.Type = lv.As("", "type")
lnk.HrefLang = lv.As("", "hreflang")
i.Links = append(i.Links, lnk)
}
}
list = item.SelectNodes(ns, "contributor")
for _, cv := range list {
i.Contributors = append(i.Contributors, cv.S("", "name"))
}
if tn = item.SelectNode(ns, "content"); tn != nil {
i.Content = new(Content)
i.Content.Type = tn.As("", "type")
//.........这里部分代码省略.........