Changed depracated xmlx Node api to new one.

This commit is contained in:
jim teeuwen 2011-05-11 17:40:56 +02:00
parent 6c565263da
commit 09a1cbe77d
3 changed files with 74 additions and 74 deletions

62
atom.go
View File

@ -49,86 +49,86 @@ func (this *Feed) readAtom(doc *xmlx.Document) (err os.Error) {
var list []*xmlx.Node var list []*xmlx.Node
for _, node := range channels { for _, node := range channels {
if ch = getChan(node.GetValue(ns, "id"), node.GetValue(ns, "title")); ch == nil { if ch = getChan(node.S(ns, "id"), node.S(ns, "title")); ch == nil {
ch = new(Channel) ch = new(Channel)
this.Channels = append(this.Channels, ch) this.Channels = append(this.Channels, ch)
} }
ch.Title = node.GetValue(ns, "title") ch.Title = node.S(ns, "title")
ch.LastBuildDate = node.GetValue(ns, "updated") ch.LastBuildDate = node.S(ns, "updated")
ch.Id = node.GetValue(ns, "id") ch.Id = node.S(ns, "id")
ch.Rights = node.GetValue(ns, "rights") ch.Rights = node.S(ns, "rights")
list = node.SelectNodes(ns, "link") list = node.SelectNodes(ns, "link")
ch.Links = make([]Link, len(list)) ch.Links = make([]Link, len(list))
for i, v := range list { for i, v := range list {
ch.Links[i].Href = v.GetAttr("", "href") ch.Links[i].Href = v.As("", "href")
ch.Links[i].Rel = v.GetAttr("", "rel") ch.Links[i].Rel = v.As("", "rel")
ch.Links[i].Type = v.GetAttr("", "type") ch.Links[i].Type = v.As("", "type")
ch.Links[i].HrefLang = v.GetAttr("", "hreflang") ch.Links[i].HrefLang = v.As("", "hreflang")
} }
if tn = node.SelectNode(ns, "subtitle"); tn != nil { if tn = node.SelectNode(ns, "subtitle"); tn != nil {
ch.SubTitle = SubTitle{} ch.SubTitle = SubTitle{}
ch.SubTitle.Type = tn.GetAttr("", "type") ch.SubTitle.Type = tn.As("", "type")
ch.SubTitle.Text = tn.Value ch.SubTitle.Text = tn.Value
} }
if tn = node.SelectNode(ns, "generator"); tn != nil { if tn = node.SelectNode(ns, "generator"); tn != nil {
ch.Generator = Generator{} ch.Generator = Generator{}
ch.Generator.Uri = tn.GetAttr("", "uri") ch.Generator.Uri = tn.As("", "uri")
ch.Generator.Version = tn.GetAttr("", "version") ch.Generator.Version = tn.As("", "version")
ch.Generator.Text = tn.Value ch.Generator.Text = tn.Value
} }
if tn = node.SelectNode(ns, "author"); tn != nil { if tn = node.SelectNode(ns, "author"); tn != nil {
ch.Author = Author{} ch.Author = Author{}
ch.Author.Name = tn.GetValue("", "name") ch.Author.Name = tn.S("", "name")
ch.Author.Uri = tn.GetValue("", "uri") ch.Author.Uri = tn.S("", "uri")
ch.Author.Email = tn.GetValue("", "email") ch.Author.Email = tn.S("", "email")
} }
itemcount := len(ch.Items) itemcount := len(ch.Items)
list = node.SelectNodes(ns, "entry") list = node.SelectNodes(ns, "entry")
for _, item := range list { for _, item := range list {
if haveItem(ch, item.GetValue(ns, "id"), item.GetValue(ns, "title"), item.GetValue(ns, "summary")) { if haveItem(ch, item.S(ns, "id"), item.S(ns, "title"), item.S(ns, "summary")) {
continue continue
} }
i = new(Item) i = new(Item)
i.Title = item.GetValue(ns, "title") i.Title = item.S(ns, "title")
i.Id = item.GetValue(ns, "id") i.Id = item.S(ns, "id")
i.PubDate = item.GetValue(ns, "updated") i.PubDate = item.S(ns, "updated")
i.Description = item.GetValue(ns, "summary") i.Description = item.S(ns, "summary")
links := item.SelectNodes(ns, "link") links := item.SelectNodes(ns, "link")
for _, lv := range links { for _, lv := range links {
if tn.GetAttr(ns, "rel") == "enclosure" { if tn.As(ns, "rel") == "enclosure" {
enc := new(Enclosure) enc := new(Enclosure)
enc.Url = lv.GetAttr("", "href") enc.Url = lv.As("", "href")
enc.Type = lv.GetAttr("", "type") enc.Type = lv.As("", "type")
i.Enclosures = append(i.Enclosures, enc) i.Enclosures = append(i.Enclosures, enc)
} else { } else {
lnk := new(Link) lnk := new(Link)
lnk.Href = lv.GetAttr("", "href") lnk.Href = lv.As("", "href")
lnk.Rel = lv.GetAttr("", "rel") lnk.Rel = lv.As("", "rel")
lnk.Type = lv.GetAttr("", "type") lnk.Type = lv.As("", "type")
lnk.HrefLang = lv.GetAttr("", "hreflang") lnk.HrefLang = lv.As("", "hreflang")
i.Links = append(i.Links, lnk) i.Links = append(i.Links, lnk)
} }
} }
list = item.SelectNodes(ns, "contributor") list = item.SelectNodes(ns, "contributor")
for _, cv := range list { for _, cv := range list {
i.Contributors = append(i.Contributors, cv.GetValue("", "name")) i.Contributors = append(i.Contributors, cv.S("", "name"))
} }
if tn = item.SelectNode(ns, "content"); tn != nil { if tn = item.SelectNode(ns, "content"); tn != nil {
i.Content = new(Content) i.Content = new(Content)
i.Content.Type = tn.GetAttr("", "type") i.Content.Type = tn.As("", "type")
i.Content.Lang = tn.GetValue("xml", "lang") i.Content.Lang = tn.S("xml", "lang")
i.Content.Base = tn.GetValue("xml", "base") i.Content.Base = tn.S("xml", "base")
i.Content.Text = tn.Value i.Content.Text = tn.Value
} }

View File

@ -209,7 +209,7 @@ func (this *Feed) GetVersionInfo(doc *xmlx.Document) (ftype string, fversion [2]
rss: rss:
if node = doc.SelectNode("", "rss"); node != nil { if node = doc.SelectNode("", "rss"); node != nil {
ftype = "rss" ftype = "rss"
version := node.GetAttr("", "version") version := node.As("", "version")
p := strings.Index(version, ".") p := strings.Index(version, ".")
major, _ := strconv.Atoi(version[0:p]) major, _ := strconv.Atoi(version[0:p])
minor, _ := strconv.Atoi(version[p+1 : len(version)]) minor, _ := strconv.Atoi(version[p+1 : len(version)])

82
rss.go
View File

@ -59,12 +59,12 @@ func (this *Feed) readRss2(doc *xmlx.Document) (err os.Error) {
channels := doc.SelectNodes(ns, "channel") channels := doc.SelectNodes(ns, "channel")
for _, node := range channels { for _, node := range channels {
if ch = getChan(node.GetValue(ns, "pubDate"), node.GetValue(ns, "title")); ch == nil { if ch = getChan(node.S(ns, "pubDate"), node.S(ns, "title")); ch == nil {
ch = new(Channel) ch = new(Channel)
this.Channels = append(this.Channels, ch) this.Channels = append(this.Channels, ch)
} }
ch.Title = node.GetValue(ns, "title") ch.Title = node.S(ns, "title")
list = node.SelectNodes(ns, "link") list = node.SelectNodes(ns, "link")
ch.Links = make([]Link, len(list)) ch.Links = make([]Link, len(list))
@ -72,20 +72,20 @@ func (this *Feed) readRss2(doc *xmlx.Document) (err os.Error) {
ch.Links[i].Href = v.Value ch.Links[i].Href = v.Value
} }
ch.Description = node.GetValue(ns, "description") ch.Description = node.S(ns, "description")
ch.Language = node.GetValue(ns, "language") ch.Language = node.S(ns, "language")
ch.Copyright = node.GetValue(ns, "copyright") ch.Copyright = node.S(ns, "copyright")
ch.ManagingEditor = node.GetValue(ns, "managingEditor") ch.ManagingEditor = node.S(ns, "managingEditor")
ch.WebMaster = node.GetValue(ns, "webMaster") ch.WebMaster = node.S(ns, "webMaster")
ch.PubDate = node.GetValue(ns, "pubDate") ch.PubDate = node.S(ns, "pubDate")
ch.LastBuildDate = node.GetValue(ns, "lastBuildDate") ch.LastBuildDate = node.S(ns, "lastBuildDate")
ch.Docs = node.GetValue(ns, "docs") ch.Docs = node.S(ns, "docs")
list = node.SelectNodes(ns, "category") list = node.SelectNodes(ns, "category")
ch.Categories = make([]*Category, len(list)) ch.Categories = make([]*Category, len(list))
for i, v := range list { for i, v := range list {
ch.Categories[i] = new(Category) ch.Categories[i] = new(Category)
ch.Categories[i].Domain = v.GetAttr(ns, "domain") ch.Categories[i].Domain = v.As(ns, "domain")
ch.Categories[i].Text = v.Value ch.Categories[i].Text = v.Value
} }
@ -94,13 +94,13 @@ func (this *Feed) readRss2(doc *xmlx.Document) (err os.Error) {
ch.Generator.Text = n.Value ch.Generator.Text = n.Value
} }
ch.TTL = node.GetValuei(ns, "ttl") ch.TTL = node.I(ns, "ttl")
ch.Rating = node.GetValue(ns, "rating") ch.Rating = node.S(ns, "rating")
list = node.SelectNodes(ns, "hour") list = node.SelectNodes(ns, "hour")
ch.SkipHours = make([]int, len(list)) ch.SkipHours = make([]int, len(list))
for i, v := range list { for i, v := range list {
ch.SkipHours[i] = int(v.GetValuei(ns, "hour")) ch.SkipHours[i] = v.I(ns, "hour")
} }
list = node.SelectNodes(ns, "days") list = node.SelectNodes(ns, "days")
@ -110,43 +110,43 @@ func (this *Feed) readRss2(doc *xmlx.Document) (err os.Error) {
} }
if n = node.SelectNode(ns, "image"); n != nil { if n = node.SelectNode(ns, "image"); n != nil {
ch.Image.Title = n.GetValue(ns, "title") ch.Image.Title = n.S(ns, "title")
ch.Image.Url = n.GetValue(ns, "url") ch.Image.Url = n.S(ns, "url")
ch.Image.Link = n.GetValue(ns, "link") ch.Image.Link = n.S(ns, "link")
ch.Image.Width = n.GetValuei(ns, "width") ch.Image.Width = n.I(ns, "width")
ch.Image.Height = n.GetValuei(ns, "height") ch.Image.Height = n.I(ns, "height")
ch.Image.Description = n.GetValue(ns, "description") ch.Image.Description = n.S(ns, "description")
} }
if n = node.SelectNode(ns, "cloud"); n != nil { if n = node.SelectNode(ns, "cloud"); n != nil {
ch.Cloud = Cloud{} ch.Cloud = Cloud{}
ch.Cloud.Domain = n.GetAttr(ns, "domain") ch.Cloud.Domain = n.As(ns, "domain")
ch.Cloud.Port = n.GetAttri(ns, "port") ch.Cloud.Port = n.Ai(ns, "port")
ch.Cloud.Path = n.GetAttr(ns, "path") ch.Cloud.Path = n.As(ns, "path")
ch.Cloud.RegisterProcedure = n.GetAttr(ns, "registerProcedure") ch.Cloud.RegisterProcedure = n.As(ns, "registerProcedure")
ch.Cloud.Protocol = n.GetAttr(ns, "protocol") ch.Cloud.Protocol = n.As(ns, "protocol")
} }
if n = node.SelectNode(ns, "textInput"); n != nil { if n = node.SelectNode(ns, "textInput"); n != nil {
ch.TextInput = Input{} ch.TextInput = Input{}
ch.TextInput.Title = n.GetValue(ns, "title") ch.TextInput.Title = n.S(ns, "title")
ch.TextInput.Description = n.GetValue(ns, "description") ch.TextInput.Description = n.S(ns, "description")
ch.TextInput.Name = n.GetValue(ns, "name") ch.TextInput.Name = n.S(ns, "name")
ch.TextInput.Link = n.GetValue(ns, "link") ch.TextInput.Link = n.S(ns, "link")
} }
itemcount := len(ch.Items) itemcount := len(ch.Items)
list = node.SelectNodes(ns, "item") list = node.SelectNodes(ns, "item")
for _, item := range list { for _, item := range list {
if haveItem(ch, item.GetValue(ns, "pubDate"), if haveItem(ch, item.S(ns, "pubDate"),
item.GetValue(ns, "title"), item.GetValue(ns, "description")) { item.S(ns, "title"), item.S(ns, "description")) {
continue continue
} }
i = new(Item) i = new(Item)
i.Title = item.GetValue(ns, "title") i.Title = item.S(ns, "title")
i.Description = item.GetValue(ns, "description") i.Description = item.S(ns, "description")
tl = node.SelectNodes(ns, "link") tl = node.SelectNodes(ns, "link")
for _, v := range tl { for _, v := range tl {
@ -160,14 +160,14 @@ func (this *Feed) readRss2(doc *xmlx.Document) (err os.Error) {
i.Author.Name = n.Value i.Author.Name = n.Value
} }
i.Comments = item.GetValue(ns, "comments") i.Comments = item.S(ns, "comments")
i.Guid = item.GetValue(ns, "guid") i.Guid = item.S(ns, "guid")
i.PubDate = item.GetValue(ns, "pubDate") i.PubDate = item.S(ns, "pubDate")
tl = item.SelectNodes(ns, "category") tl = item.SelectNodes(ns, "category")
for _, lv := range tl { for _, lv := range tl {
cat := new(Category) cat := new(Category)
cat.Domain = lv.GetAttr(ns, "domain") cat.Domain = lv.As(ns, "domain")
cat.Text = lv.Value cat.Text = lv.Value
i.Categories = append(i.Categories, cat) i.Categories = append(i.Categories, cat)
} }
@ -175,15 +175,15 @@ func (this *Feed) readRss2(doc *xmlx.Document) (err os.Error) {
tl = item.SelectNodes(ns, "enclosure") tl = item.SelectNodes(ns, "enclosure")
for _, lv := range tl { for _, lv := range tl {
enc := new(Enclosure) enc := new(Enclosure)
enc.Url = lv.GetAttr(ns, "url") enc.Url = lv.As(ns, "url")
enc.Length = lv.GetAttri64(ns, "length") enc.Length = lv.Ai64(ns, "length")
enc.Type = lv.GetAttr(ns, "type") enc.Type = lv.As(ns, "type")
i.Enclosures = append(i.Enclosures, enc) i.Enclosures = append(i.Enclosures, enc)
} }
if src := item.SelectNode(ns, "source"); src != nil { if src := item.SelectNode(ns, "source"); src != nil {
i.Source = new(Source) i.Source = new(Source)
i.Source.Url = src.GetAttr(ns, "url") i.Source.Url = src.As(ns, "url")
i.Source.Text = src.Value i.Source.Text = src.Value
} }