Pages

Thursday, December 22, 2011

XML Parsing Article iPhone


XMLParser.h

#import

@class googleNewsAppDelegate, newsModel;

@interface XMLParser : NSObject <NSXMLParserDelegate> {
    
    googleNewsAppDelegate *appDelegate;
    newsModel *aNews;
    NSMutableString *mutableString;
    BOOL isTagValue;
}

-(XMLParser *)initXMLParser;

@end


XMLParser.m

#import "XMLParser.h"
#import "googleNewsAppDelegate.h"
#import "newsModel.h"

@implementation XMLParser

-(XMLParser *)initXMLParser
{
    [super init];
    appDelegate = (googleNewsAppDelegate *)[[UIApplication sharedApplication]delegate];
    isTagValue = NO;
    return self;
}


-(void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict
{
    if([elementName isEqualToString:@"channel"])
    {
        appDelegate.mutableArrayData = [[NSMutableArray alloc] init];
    }
    else if([elementName isEqualToString:@"item"])
    {
        aNews = [[newsModel alloc] init];
        isTagValue = YES;
    }
}

-(void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
{
    if(isTagValue == YES)
    {
        if(!mutableString)
        {
            mutableString = [[NSMutableString alloc] initWithString:string];
        }
        else
        {
            [mutableString appendString:string];
        }
    }
}

-(void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
{
    if([elementName isEqualToString:@"channel"])
    {
        return;
    }
    if([elementName isEqualToString:@"item"])
    {
        [appDelegate.mutableArrayData addObject:aNews];
        [aNews release];
        aNews = nil;
    }
    else
    {
        if(isTagValue == YES && [elementName isEqualToString:@"item"] || [elementName isEqualToString:@"title"] || [elementName isEqualToString:@"description"] || [elementName isEqualToString:@"link"] || [elementName isEqualToString:@"pubDate"])
        {
            [aNews setValue:mutableString forKey:elementName];
            [mutableString release];
            mutableString = nil;
        }
    }
    NSLog(@"%@",aNews.pubDate);
}

-(void)dealloc
{
    [super dealloc];
    [mutableString release];
    [aNews release];
}

@end



DetailView.h

#import

@class newsModel;

@interface detailView : UIViewController <UITableViewDataSource, UITableViewDelegate> {
    
    newsModel *newData;
    IBOutlet UIWebView *webViewObject;
}

@property (nonatomic, retain) newsModel *newData;
@property (nonatomic, retain) IBOutlet UIWebView *webViewObject;

-(void)webViewCreateAndLoad;

@end

DetailView.m

#import "detailView.h"
#import "newsModel.h"

@implementation detailView

@synthesize newData,webViewObject;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)dealloc
{
    [super dealloc];
    [newData release];
}

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.title = @"Story";
    NSLog(@"Web View :==========>  %@ ",newData.link);
    [self webViewCreateAndLoad];
    // Do any additional setup after loading the view from its nib.
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

#pragma mark - TableView Methods

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 3;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 1;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifire = @"cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifire];
    if(cell == nil)
    {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifire]autorelease];
    }
    [tableView setBackgroundColor:[UIColor clearColor]];
    switch(indexPath.section)
    {
            case 0:
                cell.textLabel.text = newData.title;
                break;
            case 1:
                cell.textLabel.text = newData.link;
                break;
            case 2:
                cell.textLabel.text = newData.description;
                break;
    }

    return cell;
}

-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
    NSString *stringHeader = nil;
    switch(section)
    {
            case 0:
                stringHeader = [NSString stringWithString:@"Title"];
                break;
            case 1:
                stringHeader = [NSString stringWithString:@"Link"];
                break;
            case 2:
                stringHeader = [NSString stringWithString:@"Description"];
                break;
    }
    return stringHeader;
}

-(void)webViewCreateAndLoad
{
    NSURL *urlString = [NSURL URLWithString:newData.link];
    NSURLRequest *urlRequest = [[NSURLRequest alloc] initWithURL:urlString];
    [webViewObject loadRequest:urlRequest];
}

@end

Write inside AppDelegate.m 

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    
    NSURL *url = [NSURL URLWithString:@"http://news.google.com/news?ned=us&topic=h&output=rss"];
    
    NSXMLParser *xmlParser = [[NSXMLParser alloc] initWithContentsOfURL:url];
    
    XMLParser *parser = [[XMLParser alloc] initXMLParser];
    
    [xmlParser setDelegate:parser];
    
    BOOL success = [xmlParser parse];
    
    if(success)
    {
        NSLog(@"Done");
    }
    else
    {
        NSLog(@"Error");
    }
    
    // Override point for customization after application launch.
    // Add the navigation controller's view to the window and display.
    self.window.rootViewController = self.navigationController;
    [self.window makeKeyAndVisible];
    return YES;
}




Tuesday, April 20, 2010

Extended 4 File System

Extended 4 File System 
                    The ext4 file system can support volumes with sizes up to 1 exabyte[8] and files with sizes up to 16 terabytes. The current file system creation tools can only create a file system of 16TB. No information has been provided as to when this limitation will be removed.
                     It also compatible with the backward  version of the  File system  such as  Ext2, Ext3 which is represent in detail as following.
                     The ext4 file system is backward compatible with ext3 and ext2, making it possible to mount ext3 and ext2 filesystems as ext4. This will already slightly improve performance, because certain new features of ext4 can also be used with ext3 and ext2, such as the new block allocation algorithm.                                   The ext3 file system is partially forward compatible with ext4, that is, an ext4 filesystem can be mounted as an ext3 partition (using "ext3" as the filesystem type when mounting). However, if the ext4 partition uses extents (a major new feature of ext4), then the ability to mount the file system as ext3 is lost.