Trees

Using tree data structures is an excellent way to represent XML data. They allow you to create search paths through data so that you can find just the data you’re looking for, as long as you can comfortably fit the data into memory. You can retrieve all elements, search for a success value, and so forth. Trees convert text-based XML back into a multidimensional structure.

To bridge the gap between NSXMLParser and tree-based parse results, you can use an NSXMLParser-based helper class to return more standard tree-based data. This requires a simple tree node like the kind shown here:

@interface TreeNode : NSObject @property (nonatomic, weak)       TreeNode        *parent; @property (nonatomic, strong)     NSMutableArray  *children; ...

Get The Core iOS Developer’s Cookbook, Fifth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.