XML : How to unmarshall xml data using the go-pkg-rss

I'm trying to parse some RSS feeds using Go . A package I found was https://github.com/jteeuwen/go-pkg-rss

I am able to get the feeds from the server , However I am not able to unmarshall it into the structure I want. 1. Is there a way to convert the feed into []byte data 2. OR directly feed it to the unmarshall function that xml provides.? My code is here.

  import(      :       rss "github.com/jteeuwen/go-pkg-rss"      "github.com/jteeuwen/go-pkg-xmlx"  )  type Entry struct{      :      :  }  type Feed struct {      XMLName   xml.Name `xml:"feed"`      Id        string   `xml:"id"`      Logo      string   `xml:"logo"`      Generator string   `xml:"generator"`      Author    string   `xml:"author"`      Title     string   `xml:"title"`      Link      xml.Name `xml:"link"`      Entries   []Entry  `xml:"entry"`  }    func main() {      PollFeed("http://alerts.weather.gov/cap/us.atom", 5, nil)  }    func PollFeed(uri string, timeout int, cr xmlx.CharsetFunc) {      feed := rss.New(timeout, true, chanHandler, itemHandler)      if err := feed.Fetch(uri, cr); err != nil {          fmt.Printf("[e] %s: %s\n", uri, err)          return          <-time.After(time.Duration(feed.SecondsTillUpdate() * 1e9))      }  }  func chanHandler(feed *rss.Feed, newchannels []*rss.Channel) {      //dont really need to do anything  }    func itemHandler(feed *rss.Feed, ch *rss.Channel, newitems []*rss.Item){      var v Feed      fmt.Printf("%d new item(s) in %s\n", len(newitems), feed.Url)      for _, item := range newitems {          err := xml.Unmarshal([]byte(item), &v)          if err != nil {              fmt.Printf("error: %v", err)              return          }            fmt.Printf("%s, %s\n", v.Entries[0].Effective, v.Entries[0].Event)      }    }    

My question is, how do I pass get the feed into a form I can consume?

No comments:

Post a Comment