updated getExtentions to don't overwrite root node
This commit is contained in:
parent
e895d2d708
commit
bd84124886
|
@ -81,15 +81,14 @@ func Test_ItemExtensions(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)
|
||||||
|
|
||||||
edgarExtension := feed.Channels[0].Items[0].Extensions["http://www.sec.gov/Archives/edgar"]
|
edgarExtensionxbrlFiling := feed.Channels[0].Items[0].Extensions["http://www.sec.gov/Archives/edgar"]["xbrlFiling"][0].Childrens
|
||||||
|
|
||||||
companyExpected := "Cellular Biomedicine Group, Inc."
|
companyExpected := "Cellular Biomedicine Group, Inc."
|
||||||
companyName := edgarExtension["companyName"][0]
|
companyName := edgarExtensionxbrlFiling["companyName"][0]
|
||||||
if companyName.Value != companyExpected {
|
if companyName.Value != companyExpected {
|
||||||
t.Errorf("Expected company to be %s but found %s", companyExpected, companyName.Value)
|
t.Errorf("Expected company to be %s but found %s", companyExpected, companyName.Value)
|
||||||
}
|
}
|
||||||
|
|
||||||
files := edgarExtension["xbrlFiles"][0].Childrens["xbrlFile"]
|
files := edgarExtensionxbrlFiling["xbrlFiles"][0].Childrens["xbrlFile"]
|
||||||
fileSizeExpected := 10
|
fileSizeExpected := 10
|
||||||
if len(files) != 10 {
|
if len(files) != 10 {
|
||||||
t.Errorf("Expected files size to be %s but found %s", fileSizeExpected, len(files))
|
t.Errorf("Expected files size to be %s but found %s", fileSizeExpected, len(files))
|
||||||
|
|
32
rss.go
32
rss.go
|
@ -181,13 +181,10 @@ func (this *Feed) readRss2(doc *xmlx.Document) (err error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
tl = item.SelectNodes("*", "*")
|
tl = item.SelectNodes(ns, ns)
|
||||||
i.Extensions = make(map[string]map[string][]Extension)
|
i.Extensions = make(map[string]map[string][]Extension)
|
||||||
for _, lv := range tl {
|
for _, lv := range tl {
|
||||||
e, ok := getExtentions(lv)
|
getExtensions(&i.Extensions, lv)
|
||||||
if ok {
|
|
||||||
i.Extensions[lv.Name.Space] = e
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ch.Items = append(ch.Items, i)
|
ch.Items = append(ch.Items, i)
|
||||||
|
@ -197,23 +194,24 @@ func (this *Feed) readRss2(doc *xmlx.Document) (err error) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func getExtentions(node *xmlx.Node) (extentions map[string][]Extension, ok bool) {
|
func getExtensions(extensionsX *map[string]map[string][]Extension, node *xmlx.Node) {
|
||||||
extentions = make(map[string][]Extension, 0)
|
extentions := *extensionsX
|
||||||
|
|
||||||
if node.Name.Space != "" {
|
if node.Name.Space != "" {
|
||||||
for _, y := range node.Children {
|
extensione, noErrors := getExtension(node)
|
||||||
extension, ok := getExtention(y)
|
if noErrors {
|
||||||
if ok {
|
if len(extentions[node.Name.Space]) == 0 {
|
||||||
extentions[y.Name.Local] = append(extentions[y.Name.Local], extension)
|
extentions[node.Name.Space] = make(map[string][]Extension, 0)
|
||||||
}
|
}
|
||||||
|
if len(extentions[node.Name.Space][node.Name.Local]) == 0 {
|
||||||
|
extentions[node.Name.Space][node.Name.Local] = make([]Extension, 0)
|
||||||
|
}
|
||||||
|
extentions[node.Name.Space][node.Name.Local] = append(extentions[node.Name.Space][node.Name.Local], extensione)
|
||||||
}
|
}
|
||||||
ok = true
|
|
||||||
} else {
|
|
||||||
ok = false
|
|
||||||
}
|
}
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func getExtention(node *xmlx.Node) (Extension, bool) {
|
func getExtension(node *xmlx.Node) (Extension, bool) {
|
||||||
var extension Extension
|
var extension Extension
|
||||||
if node.Name.Space != "" {
|
if node.Name.Space != "" {
|
||||||
extension = Extension{Name: node.Name.Local, Value: node.GetValue()}
|
extension = Extension{Name: node.Name.Local, Value: node.GetValue()}
|
||||||
|
@ -223,7 +221,7 @@ func getExtention(node *xmlx.Node) (Extension, bool) {
|
||||||
extension.Attrs[x.Name.Local] = x.Value
|
extension.Attrs[x.Name.Local] = x.Value
|
||||||
}
|
}
|
||||||
for _, y := range node.Children {
|
for _, y := range node.Children {
|
||||||
children, ok := getExtention(y)
|
children, ok := getExtension(y)
|
||||||
if ok {
|
if ok {
|
||||||
extension.Childrens[y.Name.Local] = append(extension.Childrens[y.Name.Local], children)
|
extension.Childrens[y.Name.Local] = append(extension.Childrens[y.Name.Local], children)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue