func ExampleParseCustom() { f, err := os.Open("testdata/atom.xml") if err != nil { return } myfeed := &MyFeed{} err = feed.ParseCustom(f, myfeed, feed.DefaultOptions) if err != nil { fmt.Printf("Cannot parse feed: %s\n", err) return } fmt.Printf("FEED '%s' generated with %s\n", myfeed.Title, myfeed.Generator) for i, entry := range myfeed.Entries { fmt.Printf("\t#%v '%s' (%s)\n", i, entry.Title, entry.Link) } // Output: //FEED 'Me, Myself and I' generated with http://www.atomgenerator.com/ V1.0 // #0 'Breakfast' (http://example.org/2005/04/02/breakfast) // #1 'Dinner' (http://example.org/2005/04/02/dinner) }
func ExampleUserFeed_extension() { f, err := os.Open("testdata/rss.xml") if err != nil { return } //Manager is in github.com/apognu/xml/feed/extension manager := extension.Manager{} // we add the dc extension to it // dc extension is in "github.com/apognu/xml/feed/rss/extension/dc" dc.AddToManager(&manager) opt := feed.DefaultOptions //we pass our custom extension Manager to ParseOptions opt.ExtensionManager = manager myfeed := &ExtendedFeed{} err = feed.ParseCustom(f, myfeed, opt) if err != nil { fmt.Printf("Cannot parse feed: %s\n", err) return } fmt.Printf("FEED '%s'\n", myfeed.Title) for i, entry := range myfeed.Entries { fmt.Printf("\t#%v '%s' by %s (%s)\n", i, entry.Title, entry.Creator, entry.Link) } // Output: //FEED 'Me, Myself and I' // #0 'Breakfast' by Peter J. (http://example.org/2005/04/02/breakfast) // #1 'Dinner' by Peter J. (http://example.org/2005/04/02/dinner) }