Objective-C classes (requires ARC) to simplify:
- XML parsing
- Server communication
The classes were originally built for the Indivo Framework, hence the "IN" prefix.
Here's a quick example on how you could load an XML file (from PubMed in this case) and parse the XML to find specific nodes (MeSH headings in this case):
NSString *urlString = @"http://eutils.ncbi.nlm.nih.gov/entrez/eutils/efetch.fcgi?db=pubmed&id=23836201&retmode=xml";
NSURL *url = [NSURL URLWithString:urlString];
INURLLoader *loader = [INURLLoader loaderWithURL:url];
[loader getWithCallback:^(BOOL userDidCancel, NSString *__autoreleasing errorMessage) {
if (!errorMessage && !userDidCancel) {
// did receive XML, parse and extract MeshHeading
NSError *error = nil;
INXMLNode *root = [INXMLParser parseXML:loader.responseString error:&error];
if (root) {
NSAssert([@"PubmedArticleSet" isEqualToString:root.name], @"Expecting \"PubmedArticleSet\" to be the root XML node name, instead got \"%@\"", root.name);
NSArray *headings = [[[[root childNamed:@"PubmedArticle"] childNamed:@"MedlineCitation"] childNamed:@"MeshHeadingList"] childrenNamed:@"MeshHeading"];
// loop and log MeSH headings
for (INXMLNode *heading in headings) {
NSLog(@"=> %@", [heading childNamed:@"DescriptorName"].text);
}
}
}
}];
Wraps NSXMLParser
to simplify XML parsing and returns the XML tree as INXMLNode
objects which have DOM traversing features built after jQuery.
Wraps NSURLConnection
and NSURLResponse
into a block-based API for easy asynchronous interweb communication.
This work has been put into the public domain, meaning if you want to use some of the code found here you can do so and don't have to attribute. Enjoy!
To the extent possible under law,
Pascal Pfiffner
has waived all copyright and related or neighboring rights to
INXMLParsing.