All Projects → mattt → Ono

mattt / Ono

Licence: mit
A sensible way to deal with XML & HTML for iOS & macOS

Programming Languages

objective c
16641 projects - #2 most used programming language

Projects that are alternatives of or similar to Ono

Xml
XML without worries
Stars: ✭ 35 (-98.65%)
Mutual labels:  xml, xpath
Internettools
XPath/XQuery 3.1 interpreter for Pascal with compatibility modes for XPath 2.0/XQuery 1.0/3.0, custom and JSONiq extensions, XML/HTML parsers and classes for HTTP/S requests
Stars: ✭ 82 (-96.84%)
Mutual labels:  xml, xpath
Xom
XOM™ is a new XML object model. It is an open source (LGPL), tree-based API for processing XML with Java that strives for correctness, simplicity, and performance, in that order.
Stars: ✭ 38 (-98.54%)
Mutual labels:  xml, xpath
Nokogiri
Nokogiri (鋸) makes it easy and painless to work with XML and HTML from Ruby.
Stars: ✭ 5,748 (+121.16%)
Mutual labels:  xml, libxml2
Xquery
Extract data or evaluate value from HTML/XML documents using XPath
Stars: ✭ 155 (-94.04%)
Mutual labels:  xml, xpath
Fuzi
A fast & lightweight XML & HTML parser in Swift with XPath & CSS support
Stars: ✭ 894 (-65.6%)
Mutual labels:  xml, xpath
Jsoup
jsoup: the Java HTML parser, built for HTML editing, cleaning, scraping, and XSS safety.
Stars: ✭ 9,184 (+253.37%)
Mutual labels:  xml, xpath
Camaro
camaro is an utility to transform XML to JSON, using Node.js binding to native XML parser pugixml, one of the fastest XML parser around.
Stars: ✭ 438 (-83.15%)
Mutual labels:  xml, xpath
Didom
Simple and fast HTML and XML parser
Stars: ✭ 1,939 (-25.39%)
Mutual labels:  xml, xpath
Graphquery
GraphQuery is a query language and execution engine tied to any backend service.
Stars: ✭ 112 (-95.69%)
Mutual labels:  xml, xpath
Sirix
SirixDB is a temporal, evolutionary database system, which uses an accumulate only approach. It keeps the full history of each resource. Every commit stores a space-efficient snapshot through structural sharing. It is log-structured and never overwrites data. SirixDB uses a novel page-level versioning approach called sliding snapshot.
Stars: ✭ 638 (-75.45%)
Mutual labels:  xml, xpath
Xmlquery
xmlquery is Golang XPath package for XML query.
Stars: ✭ 209 (-91.96%)
Mutual labels:  xml, xpath
Parsel
Parsel lets you extract data from XML/HTML documents using XPath or CSS selectors
Stars: ✭ 628 (-75.84%)
Mutual labels:  xml, xpath
Amazon Mobile Sentiment Analysis
Opinion mining of Mobile reviews on Amazon platform
Stars: ✭ 19 (-99.27%)
Mutual labels:  xml, xpath
Basex
BaseX Main Repository.
Stars: ✭ 515 (-80.18%)
Mutual labels:  xml, xpath
Xqerl
Erlang XQuery 3.1 Processor
Stars: ✭ 44 (-98.31%)
Mutual labels:  xml, xpath
Xidel
Command line tool to download and extract data from HTML/XML pages or JSON-APIs, using CSS, XPath 3.0, XQuery 3.0, JSONiq or pattern matching. It can also create new or transformed XML/HTML/JSON documents.
Stars: ✭ 335 (-87.11%)
Mutual labels:  xml, xpath
Xpath
XPath package for Golang, supports HTML, XML, JSON document query.
Stars: ✭ 376 (-85.53%)
Mutual labels:  xml, xpath
Markup
A Swift package for working with HTML, XML, and other markup languages, based on libxml2.
Stars: ✭ 93 (-96.42%)
Mutual labels:  xml, xpath
Jquery Xpath
jQuery XPath plugin (with full XPath 2.0 language support)
Stars: ✭ 173 (-93.34%)
Mutual labels:  xml, xpath

Ono (斧)

Foundation lacks a convenient, cross-platform way to work with HTML and XML. NSXMLParser is an event-driven, SAX-style API that can be cumbersome to work with. NSXMLDocument, offers a more convenient DOM-style API, but is only supported on macOS.

Ono offers a sensible way to work with XML & HTML on Apple platforms in Objective-C and Swift

Whether your app needs to scrape a website, parse an RSS feed, or interface with a XML-RPC webservice, Ono will make your day a whole lot less terrible.

Ono (斧) means "axe", in homage to Nokogiri (鋸), which means "saw".

Features

  • Simple, modern API following standard Objective-C conventions, including extensive use of blocks and NSFastEnumeration
  • Extremely performant document parsing and traversal, powered by libxml2
  • Support for both XPath and CSS queries
  • Automatic conversion of date and number values
  • Correct, common-sense handling of XML namespaces for elements and attributes
  • Ability to load HTML and XML documents from either NSString or NSData
  • Full documentation
  • Comprehensive test suite

Installation

CocoaPods is the recommended method of installing Ono. Add the following line to your Podfile:

Podfile

pod 'Ono'

Usage

Swift

import Foundation
import Ono

guard let url = Bundle.main.url(forResource: "nutrition", withExtension: "xml"),
    let data = try? Data(contentsOf: url) else
{
    fatalError("Missing resource: nutrition.xml")
}

let document = try ONOXMLDocument(data: data)
document.rootElement.tag

for element in document.rootElement.children.first?.children ?? [] {
    let nutrient = element.tag
    let amount = element.numberValue!
    let unit = element.attributes["units"]!

    print("- \(amount)\(unit) \(nutrient)")
}

document.enumerateElements(withXPath: "//food/name") { (element, _, _) in
    print(element)
}

document.enumerateElements(withCSS: "food > serving[units]") { (element, _, _) in
    print(element)
}

Objective-C

#import "Ono.h"

NSData *data = ...;
NSError *error;

ONOXMLDocument *document = [ONOXMLDocument XMLDocumentWithData:data error:&error];
for (ONOXMLElement *element in document.rootElement.children) {
    NSLog(@"%@: %@", element.tag, element.attributes);
}

// Support for Namespaces
NSString *author = [[document.rootElement firstChildWithTag:@"creator" inNamespace:@"dc"] stringValue];

// Automatic Conversion for Number & Date Values
NSDate *date = [[document.rootElement firstChildWithTag:@"created_at"] dateValue]; // ISO 8601 Timestamp
NSInteger numberOfWords = [[[document.rootElement firstChildWithTag:@"word_count"] numberValue] integerValue];
BOOL isPublished = [[[document.rootElement firstChildWithTag:@"is_published"] numberValue] boolValue];

// Convenient Accessors for Attributes
NSString *unit = [document.rootElement firstChildWithTag:@"Length"][@"unit"];
NSDictionary *authorAttributes = [[document.rootElement firstChildWithTag:@"author"] attributes];

// Support for XPath & CSS Queries
[document enumerateElementsWithXPath:@"//Content" usingBlock:^(ONOXMLElement *element, NSUInteger idx, BOOL *stop) {
    NSLog(@"%@", element);
}];

Demo

Build and run the example project in Xcode to see Ono in action, or check out the provided Swift Playground.

Requirements

Ono is compatible with iOS 5 and higher, as well as macOS 10.7 and higher. It requires the libxml2 library, which is included automatically when installed with CocoaPods, or added manually by adding "libxml2.dylib" to the target's "Link Binary With Libraries" build phase.

Contact

Mattt

License

Ono is available under the MIT license. See the LICENSE file for more info.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].