Skip to content
Objective-C wrapper for <libxml/xmlreader.h>. Should be pretty efficent
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.


Objective-C wrapper for <libxml/xmlreader.h>


Include libxml2 in your project, see here

Short example XML:

    	<template id="abcd1" src="template1.pdf" />
    	<template id="abcd2" src="template1.pdf" />
    	<template id="abcd3" src="template1.pdf" />
    	<template id="abcd4" src="template1.pdf" />
	<category title="Hello World">
        <media name="Hello" src="Abc.pdf" />
        <media name="Hello2" src="Abc.pdf" />

Sample code to parse this

#import "SGPullParser.h"

NSMutableDictionary *_templates = [NSMutableDictionary dictionaryWithCapacity:5];
NSMutableDictionary *_categories = [NSMutableDictionary dictionaryWithCapacity:5];
NSData* data = ...

SGPullParser *parser = [SGPullParser parserWithData:data];
while ([parser readElement]) {

	// Using C strings saves unnecessary copy operations
	if ([parser elementHasNameC:"template"]) {
		// Of course you can use NSString objects as well
        NSString *identifier = [parser attributeWithQName:@"id"];
        NSString *src = [parser attributeWithQNameC:"src"];
        [_templates setObject:src forKey:identifier];
    } else if ([parser elementHasNameC:"category"]) {
        NSString *title = [parser attributeWithQNameC:"title"];
        NSMutableArray *links = [NSMutableArray arrayWithCapacity:10];
        // Run this loop until we reach the end of category 
        while ([parser readElementUntilC:"category"])
            if ([parser elementHasNameC:"media"]) {
                NSDictionary *media = @{@"name" : [parser attributeWithQName:@"name"],
                							@"src" : [parser attributeWithQName:@"src"]};
                [links addObject:media];
        [_categories setObject:links forKey:title];


Apache License, Version 2.0

You can’t perform that action at this time.