Latest 0.1.1
Homepage https://github.com/qokelate/SCXPathUtils
License MIT
Platforms ios 8.0, osx 10.10
Authors

CI Status
Version
License
Platform

Simple xpath solution for iOS/macOS.

Example

To run the example project, clone the repo, and run pod install from the Example directory first.


    #import "XPathUtils.h"

    // set default delimiter, default is "/"
    //    sc_xpathSetDelimiter(@"---");

    // create a object to test, maybe Dictionary or Array
    NSMutableDictionary *dds = [@{} mutableCopy];

    // set value for node, will prompt for every node if not exists.
    [dds setXPath:@"/root/yyy/3/sss" block:^id(id root_object, NSString *dest_xpath, id current_object, NSString *current_xpath) {

        NSLog(@"set value for: %@", current_xpath);

        if ([current_xpath hasSuffix:@"root"]) return [@{} mutableCopy];
        if ([current_xpath hasSuffix:@"yyy"]) return [@[] mutableCopy];
        if ([current_xpath hasSuffix:@"0"]) return @100;
        if ([current_xpath hasSuffix:@"1"]) return @"a1";
        if ([current_xpath hasSuffix:@"2"]) return @"a2";
        if ([current_xpath hasSuffix:@"3"]) return [@{} mutableCopy];
        return @"value";
    }];

    // just have a look ..........
    NSLog([dds description]);

    // read value
    NSLog(@"query1: %zd", dds.xString(@"root/yyy/2").length);
    NSLog(@"query2: %@", dds.xDictionary(@"root/yyy/3"));

    // change value for node
    [dds setXPath:@"root/yyy/1" block:^id(id root_object, NSString *dest_xpath, id current_object, NSString *current_xpath) {
        return @6000;
    }];

    // look for change
    NSLog([dds description]);

    // set nil to remove node
    [dds setXPath:@"root/yyy/3" block:^id(id root_object, NSString *dest_xpath, id current_object, NSString *current_xpath) {
        return nil;
    }];

    // look for change
    NSLog([dds description]);

Installation

SCXPathUtils is available through CocoaPods. To install
it, simply add the following line to your Podfile:

pod 'SCXPathUtils'

Author

sma11case, [email protected]

License

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

Latest podspec

{
    "name": "SCXPathUtils",
    "version": "0.1.1",
    "summary": "simple Xpath support for iOS/macOS",
    "description": "TODO: Add long description of the pod here.",
    "homepage": "https://github.com/qokelate/SCXPathUtils",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "sma11case": "[email protected]"
    },
    "source": {
        "git": "https://github.com/qokelate/SCXPathUtils.git",
        "tag": "0.1.1"
    },
    "platforms": {
        "ios": "8.0",
        "osx": "10.10"
    },
    "source_files": "SCXPathUtils/Classes/**/*"
}

Pin It on Pinterest

Share This