starting a way to get extentions #28

This commit is contained in:
Duke 2014-01-18 12:30:56 -02:00
parent 269db380a3
commit c06dd6d193
4 changed files with 113 additions and 0 deletions

View File

@ -76,6 +76,32 @@ func Test_RssAuthor(t *testing.T) {
}
}
func Test_Extensions(t *testing.T) {
content, _ := ioutil.ReadFile("testdata/extension.rss")
feed := New(1, true, chanHandler, itemHandler)
feed.FetchBytes("http://example.com", content, nil)
extension := feed.Channels[0].Items[0].Extensions["http://www.sec.gov/Archives/edgar"]
companyExpected := "Cellular Biomedicine Group, Inc."
companyName := *extension.Childrens[0]
if companyName.Value != companyExpected {
t.Errorf("Expected company to be %s but found %s", companyExpected, companyName.Value)
}
files := *extension.Childrens[11]
fileSizeExpected := 10
if len(files.Childrens) != 10 {
t.Errorf("Expected files size to be %s but found %s", fileSizeExpected, len(files.Childrens))
}
file := *files.Childrens[0]
fileExpected := "cbmg_10qa.htm"
if file.Attrs["file"] != fileExpected {
t.Errorf("Expected file to be %s but found %s", fileExpected, len(file.Attrs["file"]))
}
}
func Test_CData(t *testing.T) {
content, _ := ioutil.ReadFile("testdata/iosBoardGameGeek.rss")
feed := New(1, true, chanHandler, itemHandler)

View File

@ -23,6 +23,8 @@ type Item struct {
Generator *Generator
Contributors []string
Content *Content
Extensions map[string]*Extension
}
func (i *Item) Key() string {

37
rss.go
View File

@ -6,6 +6,13 @@ import (
xmlx "github.com/jteeuwen/go-pkg-xmlx"
)
type Extension struct {
Name string
Value string
Attrs map[string]string
Childrens []*Extension
}
var days = map[string]int{
"Monday": 1,
"Tuesday": 2,
@ -174,9 +181,39 @@ func (this *Feed) readRss2(doc *xmlx.Document) (err error) {
}
}
tl = item.SelectNodes("*", "*")
i.Extensions = make(map[string]*Extension)
for _, lv := range tl {
e, ok := getExtension(lv)
if ok {
i.Extensions[lv.Name.Space] = e
}
}
ch.Items = append(ch.Items, i)
}
}
this.Channels = foundChannels
return
}
func getExtension(node *xmlx.Node) (*Extension, bool) {
if node.Name.Space != "" {
var extension Extension
extension = Extension{Name: node.Name.Local, Value: node.GetValue()}
extension.Attrs = make(map[string]string)
for _, x := range node.Attributes {
extension.Attrs[x.Name.Local] = x.Value
}
for _, y := range node.Children {
if c, ok := getExtension(y); ok {
extension.Childrens = append(extension.Childrens, c)
}
}
return &extension, true
} else {
return nil, false
}
}

48
testdata/extension.rss vendored Normal file
View File

@ -0,0 +1,48 @@
<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
<channel>
<title>Extensions Test</title>
<link>http://test.extensions.net</link>
<description>Just a Test</description>
<language>en-US</language>
<lastBuildDate>Wed, 27 Mar 2013 12:30:18 PDT</lastBuildDate>
<image>
<link>http://test.extensions.net</link>
<url>http://test.extensions.net/test.jpg</url>
<title>Extensions Test</title>
</image>
<item>
<title>Cellular Biomedicine Group, Inc. (0001378624) (Filer)</title>
<link>http://www.sec.gov/Archives/edgar/data/1378624/000135448813006749/0001354488-13-006749-index.htm</link>
<guid>http://www.sec.gov/Archives/edgar/data/1378624/000135448813006749/0001354488-13-006749-xbrl.zip</guid>
<enclosure url="http://www.sec.gov/Archives/edgar/data/1378624/000135448813006749/0001354488-13-006749-xbrl.zip" length="133879" type="application/zip" />
<description>10-Q/A</description>
<pubDate>Fri, 06 Dec 2013 17:29:22 EST</pubDate>
<edgar:xbrlFiling xmlns:edgar="http://www.sec.gov/Archives/edgar">
<edgar:companyName>Cellular Biomedicine Group, Inc.</edgar:companyName>
<edgar:formType>10-Q/A</edgar:formType>
<edgar:filingDate>12/06/2013</edgar:filingDate>
<edgar:cikNumber>0001378624</edgar:cikNumber>
<edgar:accessionNumber>0001354488-13-006749</edgar:accessionNumber>
<edgar:fileNumber>000-52282</edgar:fileNumber>
<edgar:acceptanceDatetime>20131206172922</edgar:acceptanceDatetime>
<edgar:period>20130630</edgar:period>
<edgar:assistantDirector>7</edgar:assistantDirector>
<edgar:assignedSic>6199</edgar:assignedSic>
<edgar:fiscalYearEnd>1231</edgar:fiscalYearEnd>
<edgar:xbrlFiles>
<edgar:xbrlFile edgar:sequence="1" edgar:file="cbmg_10qa.htm" edgar:type="10-Q/A" edgar:size="2367019" edgar:description="CURRENT REPORT AMENDMENT" edgar:url="http://www.sec.gov/Archives/edgar/data/1378624/000135448813006749/cbmg_10qa.htm" />
<edgar:xbrlFile edgar:sequence="2" edgar:file="cbmg_ex311.htm" edgar:type="EX-31.1" edgar:size="19198" edgar:description="CERTIFICATION" edgar:url="http://www.sec.gov/Archives/edgar/data/1378624/000135448813006749/cbmg_ex311.htm" />
<edgar:xbrlFile edgar:sequence="3" edgar:file="cbmg_ex312.htm" edgar:type="EX-31.2" edgar:size="18548" edgar:description="CERTIFICATION" edgar:url="http://www.sec.gov/Archives/edgar/data/1378624/000135448813006749/cbmg_ex312.htm" />
<edgar:xbrlFile edgar:sequence="4" edgar:file="cbmg_ex321.htm" edgar:type="EX-32.1" edgar:size="9490" edgar:description="CERTIFICATION" edgar:url="http://www.sec.gov/Archives/edgar/data/1378624/000135448813006749/cbmg_ex321.htm" />
<edgar:xbrlFile edgar:sequence="5" edgar:file="cmbg-20130630.xml" edgar:type="EX-101.INS" edgar:size="1535753" edgar:description="" edgar:url="http://www.sec.gov/Archives/edgar/data/1378624/000135448813006749/cmbg-20130630.xml" />
<edgar:xbrlFile edgar:sequence="6" edgar:file="cmbg-20130630.xsd" edgar:type="EX-101.SCH" edgar:size="48804" edgar:description="" edgar:url="http://www.sec.gov/Archives/edgar/data/1378624/000135448813006749/cmbg-20130630.xsd" />
<edgar:xbrlFile edgar:sequence="7" edgar:file="cmbg-20130630_cal.xml" edgar:type="EX-101.CAL" edgar:size="60044" edgar:description="" edgar:url="http://www.sec.gov/Archives/edgar/data/1378624/000135448813006749/cmbg-20130630_cal.xml" />
<edgar:xbrlFile edgar:sequence="8" edgar:file="cmbg-20130630_def.xml" edgar:type="EX-101.DEF" edgar:size="138211" edgar:description="" edgar:url="http://www.sec.gov/Archives/edgar/data/1378624/000135448813006749/cmbg-20130630_def.xml" />
<edgar:xbrlFile edgar:sequence="9" edgar:file="cmbg-20130630_lab.xml" edgar:type="EX-101.LAB" edgar:size="264038" edgar:description="" edgar:url="http://www.sec.gov/Archives/edgar/data/1378624/000135448813006749/cmbg-20130630_lab.xml" />
<edgar:xbrlFile edgar:sequence="10" edgar:file="cmbg-20130630_pre.xml" edgar:type="EX-101.PRE" edgar:size="247808" edgar:description="" edgar:url="http://www.sec.gov/Archives/edgar/data/1378624/000135448813006749/cmbg-20130630_pre.xml" />
</edgar:xbrlFiles>
</edgar:xbrlFiling>
</item>
</channel>