NetNewsWire/Frameworks/RSXML
Brent Simmons 05a90742a6 Add RSXML framework. 2017-05-22 13:06:02 -07:00
..
RSXML Add RSXML framework. 2017-05-22 13:06:02 -07:00
RSXML.xcodeproj Add RSXML framework. 2017-05-22 13:06:02 -07:00
RSXMLTests Add RSXML framework. 2017-05-22 13:06:02 -07:00
RSXMLiOS Add RSXML framework. 2017-05-22 13:06:02 -07:00
LICENSE Add RSXML framework. 2017-05-22 13:06:02 -07:00
README.md Add RSXML framework. 2017-05-22 13:06:02 -07:00

README.md

RSXML

This is utility code for parsing XML and HTML using libXML2s SAX parser.

It builds two framework targets: one for Mac, one for iOS. It does not depend on any other third-party frameworks. The code is Objective-C with ARC.

The gist

To parse XML, create an RSSAXParserDelegate. (There are examples in the framework that you can crib from.)

To parse HTML, create an RSSAXHTMLParserDelegate. (There are examples for this too.)

Goodies and Extras

There are three XML parsers included, for OPML, RSS, and Atom. To parse OPML, see RSOPMLParser. To parse RSS and Atom, see RSFeedParser.

These parsers may or may not be complete enough for your needs. You could, in theory, start writing an RSS reader just with these. (And, if you want to, go for it, with my blessing.)

There are two HTML parsers included. RSHTMLMetadataParser pulls metadata from the head section of an HTML document. RSHTMLLinkParser pulls all the links (anchors, <a href=…> tags) from an HTML document.

Other possibly interesting things:

RSDateParser makes it easy to parse dates in the formats found in various types of feeds.

NSString+RSXML decodes HTML entities.

Also note: there are some unit tests.

Why use libXML2s SAX API?

SAX is kind of a pain because of all the state you have to manage. But its fastest and uses the least amount of memory.

An alternative is to use NSXMLParser, which is event-driven like SAX. However, RSXML was written to avoid allocating Objective-C objects except when absolutely needed. Youll note use of things like memcp and strncmp.

Normally I avoid this kind of thing strenuously. I prefer to work at the highest level possible.

But my more-than-a-decade of experience parsing XML has led me to this solution, which — last time I checked, which was, admittedly, a few years ago — was not only fastest but also uses the least memory. (The two things are related, of course: creating objects is bad for performance, so this code attempts to do the minimum possible.)

All that low-level stuff is encapsulated, however. If you parse a feed, for instance, the caller gets an RSParsedFeed which contains RSParsedArticles, and theyre standard Objective-C objects. Its only inside your RSSAXParserDelegate and RSSAXHTMLParserDelegate where youll need to deal with C.