Exemplo n.º 1
0
Arquivo: parser.go Projeto: husio/apps
// Parse parses an xml feed into an atom.Feed
func (ap *Parser) Parse(feed io.Reader) (*Feed, error) {
	fr := shared.NewXMLSanitizerReader(feed)
	p := xpp.NewXMLPullParser(fr, false, charset.NewReaderLabel)

	_, err := shared.FindRoot(p)
	if err != nil {
		return nil, err
	}

	return ap.parseRoot(p)
}
Exemplo n.º 2
0
// DetectFeedType attempts to determine the type of feed
// by looking for specific xml elements unique to the
// various feed types.
func DetectFeedType(feed io.Reader) FeedType {
	fr := shared.NewXMLSanitizerReader(feed)
	p := xpp.NewXMLPullParser(fr, false, charset.NewReaderLabel)

	_, err := shared.FindRoot(p)
	if err != nil {
		return FeedTypeUnknown
	}

	name := strings.ToLower(p.Name)
	switch name {
	case "rdf":
		return FeedTypeRSS
	case "rss":
		return FeedTypeRSS
	case "feed":
		return FeedTypeAtom
	default:
		return FeedTypeUnknown
	}
}