fixed same extentions space on root level

This commit is contained in:
Duke 2014-01-18 14:07:37 -02:00
parent c06dd6d193
commit 7daa266b18
3 changed files with 5 additions and 4 deletions

View File

@ -81,7 +81,7 @@ func Test_Extensions(t *testing.T) {
feed := New(1, true, chanHandler, itemHandler) feed := New(1, true, chanHandler, itemHandler)
feed.FetchBytes("http://example.com", content, nil) feed.FetchBytes("http://example.com", content, nil)
extension := feed.Channels[0].Items[0].Extensions["http://www.sec.gov/Archives/edgar"] extension := feed.Channels[0].Items[0].Extensions["http://www.sec.gov/Archives/edgar"][0]
companyExpected := "Cellular Biomedicine Group, Inc." companyExpected := "Cellular Biomedicine Group, Inc."
companyName := *extension.Childrens[0] companyName := *extension.Childrens[0]

View File

@ -24,7 +24,7 @@ type Item struct {
Contributors []string Contributors []string
Content *Content Content *Content
Extensions map[string]*Extension Extensions map[string][]*Extension
} }
func (i *Item) Key() string { func (i *Item) Key() string {

5
rss.go
View File

@ -182,11 +182,11 @@ func (this *Feed) readRss2(doc *xmlx.Document) (err error) {
} }
tl = item.SelectNodes("*", "*") tl = item.SelectNodes("*", "*")
i.Extensions = make(map[string]*Extension) i.Extensions = make(map[string][]*Extension)
for _, lv := range tl { for _, lv := range tl {
e, ok := getExtension(lv) e, ok := getExtension(lv)
if ok { if ok {
i.Extensions[lv.Name.Space] = e i.Extensions[lv.Name.Space] = append(i.Extensions[lv.Name.Space], e)
} }
} }
@ -202,6 +202,7 @@ func getExtension(node *xmlx.Node) (*Extension, bool) {
var extension Extension var extension Extension
extension = Extension{Name: node.Name.Local, Value: node.GetValue()} extension = Extension{Name: node.Name.Local, Value: node.GetValue()}
extension.Attrs = make(map[string]string) extension.Attrs = make(map[string]string)
for _, x := range node.Attributes { for _, x := range node.Attributes {
extension.Attrs[x.Name.Local] = x.Value extension.Attrs[x.Name.Local] = x.Value
} }