Skip to content

Helper class for parsing XML feeds in iOS using NSXMLParser. Parse simple XML in 2 lines of code.

License

Notifications You must be signed in to change notification settings

gianpiero/KMXMLParser

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

#KMXMLParser

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

NB: The Swift code is still pretty rough but it's functioning.

###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:

    var parser : KMXMLParser = KMXMLParser.alloc().initWithURL(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.objectAtIndex(0) as NSDictionary
    var title = dict.objectForKey("title") as String
  • You can also get the summary, date, and link using the appropriate key.

###License

The MIT License

Copyright 2011-2015 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.

About

Helper class for parsing XML feeds in iOS using NSXMLParser. Parse simple XML in 2 lines of code.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Objective-C 69.5%
  • Swift 30.5%