10000 GitHub - sketch204/AtomParser: A Swift package for parsing Atom and RSS feeds
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

sketch204/AtomParser

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

41 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

AtomParser

This package is can parse Atom and RSS feeds.

Usage

Parsing can be sourced through a URL, however it is highly recommended that users download the feed themselves before feeding it into the parser.

Assuming you have the feed downloaded, here is how you would parse it.

let rawFeedData: Data = downloadFeed()

let parser = try 
6261
FeedParser(data: rawFeedData)
let feed = parser.parse()

The parse function above returns a struct that will conform to the FeedFormat protocol. This protocol has no requirements and servers as a marker type. RSS and Atom have significantly different data models. Therefore there are two dedicated sets of types to define a feed. For RSS the top level type is RSS. For Atom feeds the top level type is Feed.

Once you have a parsed feed, you can check which underlying feed type it is by doing a type check.

if let atomFeed = feed as? Feed {
    // It is an atom feed. Do something with it.
}
else if let rssFeed = feed as? RSS {
    // It is an RSS feed. Do something with it.
}
else {
    fatalError("This should never happen")
}

Alternatively, if you know the type of feed you are working with, both the Feed and RSS types support direct parsing through one of their init(contentsOf url: URL), init(data: Data) or init(string: String) initializers.

About

A Swift package for parsing Atom and RSS feeds

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

0