SHXMLParser 1.1.0

SHXMLParser 1.1.0

LangLanguage Obj-CObjective C
License MIT
ReleasedLast Release Dec 2014

Maintained by Unclaimed.

  • By
  • Narasimharaj C

Easy to use automatic XML Parser built on NSXMLParser. Convert your XML data into native 'Obj C object' in just 2 steps.

How To Use:

Add the library folder SHXMLParser to your project.

XML Sample

        <item id='1'>
            <title>I am under surveillance by Canadian agents, my computer has been backdoored</title>
            <description><a href="">Comments</a></description>
        <item id='2'>
            <title>Why I Like Go</title>
            <description><a href="">Comments</a></description>

Use the below code to get the Array of Dictionary Objects from an XML like the one above. Attributes will be taken automatically.

SHXMLParser     *parser         = [[SHXMLParser alloc] init];
NSDictionary    *resultObject   = [parser parseData:self.webServicesData];
NSArray         *dataArray      = [SHXMLParser getDataAtPath:@"" fromResultObject:resultObject];

Note: In case, the path used ("") contains only one item, NSDictionary will be returned instead of NSArray. If the path leads to leaf with just a string value, string value will be returned.

If you want to convert dictionary objects in your data array into a class object for type safety, use code below.

NSArray *classVariables = [NSArray arrayWithObjects:@"title", @"link", @"comments", @"description", nil];
self.dataItems = [SHXMLParser convertDictionaryArray:dataArray toObjectArrayWithClassName:@"DataItem" classVariables:classVariables];

Note that for above conversion, class named 'DataItem' should contain public variables as mentioned in array 'classVariables', otherwise you will get runtime error.

Thats it, no need to write lot of node and element specific parsing code to retrieve data using NSXMLParser from XML data.

Requirements It requires iOS 5.0+ and uses ARC. It is built and tested using Xcode 4.5+.

Feel free to fork and update the library

License MIT License