841 | Ono (斧)
842 | 843 |A sensible way to deal with XML & HTML for iOS & Mac OS X
844 | 845 |846 |848 | 849 |Ono (斧) means "axe", in homage to Nokogiri (鋸), which means "saw".
847 |
850 | Usage
851 | 852 |#import "Ono.h"
853 |
854 | NSData *data = ...;
855 | NSError *error;
856 |
857 | ONOXMLDocument *document = [ONOXMLDocument XMLDocumentWithData:data error:&error];
858 | for (ONOXMLElement *element in document.rootElement.children) {
859 | NSLog(@"%@: %@", element.tag, element.attributes);
860 | }
861 |
862 | // Support for Namespaces
863 | NSString *author = [[document.rootElement firstChildWithTag:@"creator" inNamespace:@"dc"] stringValue];
864 |
865 | // Automatic Conversion for Number & Date Values
866 | NSDate *date = [[document.rootElement firstChildWithTag:@"created_at"] dateValue]; // ISO 8601 Timestamp
867 | NSInteger numberOfWords = [[document.rootElement firstChildWithTag:@"word_count"] numberValue] integerValue];
868 | BOOL isPublished = [[document.rootElement firstChildWithTag:@"is_published"] numberValue] boolValue];
869 |
870 | // Convenient Accessors for Attributes
871 | NSString *unit = [document.rootElement firstChildWithTag:@"Length"][@"unit"]
872 | NSDictionary *authorAttributes = [[document.rootElement firstChildWithTag:@"author"] attributes];
873 |
874 | // Support for XPath & CSS Queries
875 | [document enumerateElementsWithXPath:@"//Content" block:^(ONOXMLElement *element) {
876 | NSLog(@"%@", element);
877 | }];
878 | 881 | Contact
882 | 883 | 885 | 886 |887 | License
888 | 889 |Ono is available under the MIT license. See the LICENSE file for more info.