在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):mattt/Ono开源软件地址(OpenSource Url):https://github.com/mattt/Ono开源编程语言(OpenSource Language):Objective-C 98.2%开源软件介绍(OpenSource Introduction):Ono (斧)Foundation lacks a convenient, cross-platform way to work with HTML and XML.
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.
Features
InstallationCocoaPods is the recommended method of installing Ono.
Add the following line to your Podfilepod 'Ono' UsageSwiftimport 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);
}]; DemoBuild and run the example project in Xcode to see RequirementsOno is compatible with iOS 5 and higher, as well as macOS 10.7 and higher.
It requires the ContactLicenseOno is available under the MIT license. See the LICENSE file for more info. |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论