{"id":15621575,"url":"https://github.com/mattt/ono","last_synced_at":"2025-05-14T23:04:23.228Z","repository":{"id":14324494,"uuid":"17033786","full_name":"mattt/Ono","owner":"mattt","description":"A sensible way to deal with XML \u0026 HTML for iOS \u0026 macOS","archived":false,"fork":false,"pushed_at":"2020-04-08T03:37:13.000Z","size":320,"stargazers_count":2606,"open_issues_count":7,"forks_count":197,"subscribers_count":55,"default_branch":"master","last_synced_at":"2025-05-14T23:04:03.514Z","etag":null,"topics":["css","html","libxml2","objective-c","swift","xml","xpath"],"latest_commit_sha":null,"homepage":"","language":"Objective-C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mattt.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-02-20T20:05:54.000Z","updated_at":"2025-04-04T16:59:06.000Z","dependencies_parsed_at":"2022-07-22T12:32:50.136Z","dependency_job_id":null,"html_url":"https://github.com/mattt/Ono","commit_stats":null,"previous_names":[],"tags_count":18,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mattt%2FOno","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mattt%2FOno/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mattt%2FOno/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mattt%2FOno/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mattt","download_url":"https://codeload.github.com/mattt/Ono/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254243358,"owners_count":22038046,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["css","html","libxml2","objective-c","swift","xml","xpath"],"created_at":"2024-10-03T09:51:00.637Z","updated_at":"2025-05-14T23:04:23.205Z","avatar_url":"https://github.com/mattt.png","language":"Objective-C","readme":"# Ono (斧)\n\nFoundation lacks a convenient, cross-platform way to work with HTML and XML.\n[`NSXMLParser`](https://developer.apple.com/documentation/foundation/nsxmlparser?language=objc)\nis an event-driven,\n[\u003cabbr title=\"Simple API for XML\"\u003eSAX\u003c/abbr\u003e](https://en.wikipedia.org/wiki/Simple_API_for_XML)-style API\nthat can be cumbersome to work with.\n[`NSXMLDocument`](https://developer.apple.com/documentation/foundation/nsxmldocument),\noffers a more convenient\n[\u003cabbr title=\"Document Object Model\"\u003eDOM\u003c/abbr\u003e](https://en.wikipedia.org/wiki/Document_Object_Model)-style API,\nbut is only supported on macOS.\n\n**Ono offers a sensible way to work with XML \u0026 HTML on Apple platforms in Objective-C and Swift**\n\nWhether your app needs to\nscrape a website, parse an RSS feed, or interface with a XML-RPC webservice,\nOno will make your day a whole lot less terrible.\n\n\u003e Ono (斧) means \"axe\", in homage to [Nokogiri](http://nokogiri.org) (鋸), which means \"saw\".\n\n## Features\n\n- [x] Simple, modern API following standard Objective-C conventions, including extensive use of blocks and `NSFastEnumeration`\n- [x] Extremely performant document parsing and traversal, powered by `libxml2`\n- [x] Support for both [XPath](http://en.wikipedia.org/wiki/XPath) and [CSS](http://en.wikipedia.org/wiki/Cascading_Style_Sheets) queries\n- [x] Automatic conversion of date and number values\n- [x] Correct, common-sense handling of XML namespaces for elements and attributes\n- [x] Ability to load HTML and XML documents from either `NSString` or `NSData`\n- [x] Full documentation\n- [x] Comprehensive test suite\n\n## Installation\n\n[CocoaPods](http://cocoapods.org) is the recommended method of installing Ono.\nAdd the following line to your `Podfile`:\n\n#### Podfile\n\n```ruby\npod 'Ono'\n```\n\n## Usage\n\n### Swift\n\n```swift\nimport Foundation\nimport Ono\n\nguard let url = Bundle.main.url(forResource: \"nutrition\", withExtension: \"xml\"),\n    let data = try? Data(contentsOf: url) else\n{\n    fatalError(\"Missing resource: nutrition.xml\")\n}\n\nlet document = try ONOXMLDocument(data: data)\ndocument.rootElement.tag\n\nfor element in document.rootElement.children.first?.children ?? [] {\n    let nutrient = element.tag\n    let amount = element.numberValue!\n    let unit = element.attributes[\"units\"]!\n\n    print(\"- \\(amount)\\(unit) \\(nutrient)\")\n}\n\ndocument.enumerateElements(withXPath: \"//food/name\") { (element, _, _) in\n    print(element)\n}\n\ndocument.enumerateElements(withCSS: \"food \u003e serving[units]\") { (element, _, _) in\n    print(element)\n}\n```\n\n### Objective-C\n\n```objective-c\n#import \"Ono.h\"\n\nNSData *data = ...;\nNSError *error;\n\nONOXMLDocument *document = [ONOXMLDocument XMLDocumentWithData:data error:\u0026error];\nfor (ONOXMLElement *element in document.rootElement.children) {\n    NSLog(@\"%@: %@\", element.tag, element.attributes);\n}\n\n// Support for Namespaces\nNSString *author = [[document.rootElement firstChildWithTag:@\"creator\" inNamespace:@\"dc\"] stringValue];\n\n// Automatic Conversion for Number \u0026 Date Values\nNSDate *date = [[document.rootElement firstChildWithTag:@\"created_at\"] dateValue]; // ISO 8601 Timestamp\nNSInteger numberOfWords = [[[document.rootElement firstChildWithTag:@\"word_count\"] numberValue] integerValue];\nBOOL isPublished = [[[document.rootElement firstChildWithTag:@\"is_published\"] numberValue] boolValue];\n\n// Convenient Accessors for Attributes\nNSString *unit = [document.rootElement firstChildWithTag:@\"Length\"][@\"unit\"];\nNSDictionary *authorAttributes = [[document.rootElement firstChildWithTag:@\"author\"] attributes];\n\n// Support for XPath \u0026 CSS Queries\n[document enumerateElementsWithXPath:@\"//Content\" usingBlock:^(ONOXMLElement *element, NSUInteger idx, BOOL *stop) {\n    NSLog(@\"%@\", element);\n}];\n```\n\n## Demo\n\nBuild and run the example project in Xcode to see `Ono` in action,\nor check out the provided Swift Playground.\n\n## Requirements\n\nOno is compatible with iOS 5 and higher, as well as macOS 10.7 and higher.\nIt requires the `libxml2` library,\nwhich is included automatically when installed with CocoaPods,\nor added manually by adding \"libxml2.dylib\"\nto the target's \"Link Binary With Libraries\" build phase.\n\n## Contact\n\n[Mattt](https://twitter.com/mattt)\n\n## License\n\nOno is available under the MIT license.\nSee the LICENSE file for more info.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmattt%2Fono","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmattt%2Fono","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmattt%2Fono/lists"}