Well I’ve been busy. Whilst working on Simon’s UI tooling I decided that one of a the features I wanted to add was the ability use a basic XPath style expression to navigate a user interface. For example
/window//myView//myButton
or something similar. I remembered I had some code sitting in dXml which performed basic xpath expressions against a XML Soap message returned from a web service. So I extracted out the code an have been converting it to be a generic library which can execute xpath like expressions against anything that implements a marker interface.
This new library is called dNodi
Here’s an example of using it:
#import <dNodi/DNNode.h>
#import <dNodi/DNExecutor.h>
#import <NSObject+dNodi.h>
...
// The root node of your datastructure.
NSObject<DNNode> *rootNode = ...;
DNExecutor *executor = [[DNExecutor alloc] initWithRootNode:rootNode];
NSError *error = nil;
NSArray *results = [executor executeQuery:@"/rootNode/subnode" errorVar:&error];
if (results == nil) {
// There's an error!
}
NSObject<DNNode> *firstFoundSubNode = [results nodeAtIndex:0];
This makes things really simple. The nodes must implement the DNNode protocol which contains only 4 methods for returns the sub nodes, name, attributes, etc. so generally speaking it’s not too onerous to implement.
I hope you find it useful.