This repository has been archived by the owner on Apr 4, 2023. It is now read-only.
forked from mattn/go-pkg-rss
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathatom.go
113 lines (96 loc) · 2.92 KB
/
atom.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
package feeder
import xmlx "github.com/mattn/go-pkg-xmlx"
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, "published")
i.Updated = 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")
}
ch.Items = append(ch.Items, i)
}
}
this.Channels = foundChannels
return
}