Helper class for parsing XML feeds in iOS using NSXMLParser. Parse simple XML in 2 lines of code.
Objective-C Swift
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
Objective-c
Swift
.gitignore
LICENSE.mdown
README.mdown

README.mdown

#KMXMLParser

Follow the instructions below or check out the Objective-c and Swift sample projects.

###How to use - Objective-c

  • Drag KMXMLParser.m and KMXMLParser.h into your Xcode project. Make sure to check the "Copy items into destination group's folder" box and add the files to your target.

  • At the top of the class you want to parse the XML file #import "KMXMLParser.h"

  • To parse your file you need to use the following code:

    KMXMLParser *km = [[KMXMLParser alloc] initWithURL:url delegate:self]; 

    NSMutableArray *posts = [km posts];
  • This will return a mutable array containing all data from the feed (title, date, summary, link). If you want an array with only one of those four pieces of data specify the tag:
    NSMutableArray *posts = [km postsWithTag:@"title"];
  • Your posts array will now contain all the data from the XML. You can access it using the relevent key. For example, if you want the title of the most recent post you would use:
    [[posts objectAtIndex:0] objectForKey@"title"]);
  • You can also get the summary, date, and link using the appropriate key.

###How to use - Swift

  • Drag KMXMLParser.swift into your Xcode project. Make sure to check the "Copy items into destination group's folder" box and add the files to your target.

  • To parse your file you need to use the following code:

    let parser = KMXMLParser(url: url!) as KMXMLParser 
    dataArray = parser.posts
  • Your data array will now contain all the data from the XML. You can access it using the relevant key. For example, if you want the title of the most recent post you would use:
    var dict : NSDictionary! = dataArray.object(at: 0) as NSDictionary
    var title = dict.object(forKey: "title") as String
  • You can also get the summary, date, and link using the appropriate key.

###License

The MIT License

Copyright 2011-2017 Kieran McGrady

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.