Thursday, 25 June 2015

XML Parser

ViewController.h

#import <UIKit/UIKit.h>
#define ITEM_NAME @"name"
#define FOOD @"food"
#define ITEM_PRICE @"price"
#define ITEM_DESCRIPTION @"description"
#define ITEM_CALORIES @"calories"

@interface ViewController : UIViewController<NSXMLParserDelegate,UITableViewDataSource,UITableViewDelegate>
{
    IBOutlet UITableView *tblxml;
    NSMutableArray *arraydata;
}
@end


ViewController.m

  #import "ViewController.h"

@interface ViewController ()
{
    NSXMLParser *parser;
   
    NSMutableDictionary *currentData;
    NSString *currentElement;
}
@end

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    NSString *xmlFilePath = [[NSBundle mainBundle] pathForResource:@"food" ofType:@"xml"];
   
    parser = [[NSXMLParser alloc]initWithContentsOfURL:[NSURL fileURLWithPath:xmlFilePath]];
   
    [parser setDelegate:self];
    [parser parse];
   
    if (!arraydata)
    {
        arraydata = [[NSMutableArray alloc]init];
    }

}


- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDic
{
    NSLog(@"Did start element");
   
    currentElement = elementName;
   
    if ( [elementName isEqualToString:FOOD])
    {
        if (!currentData) {
            currentData = [[NSMutableDictionary alloc]init];
        }
       
        NSLog(@"found rootElement");
        return;
    }
}


- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
{
    NSLog(@"Did end element");
   
    if ([elementName isEqualToString:ITEM_PRICE]) {
        currentElement = elementName;
    }else if ([elementName isEqualToString:ITEM_NAME]){
        currentElement = elementName;    }
    else if ([elementName isEqualToString:ITEM_DESCRIPTION]){
        currentElement = elementName;
    }else if ([elementName isEqualToString:ITEM_CALORIES]){
        currentElement = elementName;
    }else{
        currentElement = @"";
    }
   
    if ([elementName isEqualToString:FOOD])
    {
        if (arraydata == nil) {
            arraydata= [[NSMutableArray alloc]init];
        }
       
        [arraydata addObject:[currentData copy]];
        [currentData removeAllObjects];
    }

}


- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
{
    if ([string rangeOfString:@"\n"].location == NSNotFound) {
        if ([currentElement isEqualToString:ITEM_PRICE]) {
            [currentData setObject:string forKey:ITEM_PRICE];
        }else if ([currentElement isEqualToString:ITEM_NAME]){
            [currentData setObject:string forKey:ITEM_NAME];
        }else if ([currentElement isEqualToString:ITEM_DESCRIPTION]){
            [currentData setObject:string forKey:ITEM_DESCRIPTION];
        }else if ([currentElement isEqualToString:ITEM_CALORIES]){
            [currentData setObject:string forKey:ITEM_CALORIES];
        }
    }
   
}

-(void)parserDidStartDocument:(NSXMLParser *)parser
{
    NSLog(@"StartDocument");
   
}

- (void)parserDidEndDocument:(NSXMLParser *)parser{
   
    NSLog(@"%@",arraydata);
   
    [tblxml reloadData];
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return arraydata.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
   
    NSDictionary *currentItemDetails = [arraydata objectAtIndex:indexPath.row];
   
    cell.textLabel.text = [currentItemDetails objectForKey:ITEM_NAME];
    cell.textLabel.text = [currentItemDetails objectForKey:ITEM_PRICE];
    cell.textLabel.text = [currentItemDetails objectForKey:ITEM_DESCRIPTION];
    cell.textLabel.text = [NSString stringWithFormat:@"Calories :: %@",  [currentItemDetails objectForKey:ITEM_CALORIES]];
   
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 125;
}


- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end


JSON Parser


#import "ViewController.h"

@interface ViewController ()
{
    NSMutableDictionary *arraykey;
    NSMutableArray *arraydata;
}
@end

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
   
    NSURLRequest *request = [[NSURLRequest alloc]initWithURL:[NSURL URLWithString:@"http://www.json-generator.com/api/json/get/bUyjbCQmxu?indent=2"]];

    [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError)
    {
        if (!connectionError) {
            arraykey = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
            arraydata = [[NSMutableArray alloc]init];
            [arraydata addObjectsFromArray:[[[arraykey objectForKey:@"items"]objectAtIndex:0] allKeys]];
            NSLog(@"%@",arraydata);
            NSLog(@"%@",arraykey);
            [tbljson reloadData];
        } else {
            NSLog(@"error: %@",[connectionError localizedDescription]);
        }
    }];
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return arraydata.count;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"reusecell"];
   
    if (cell==nil) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"reusecell"];
    }
   
   cell .textLabel.text = [arraydata objectAtIndex:indexPath.row];
   
    return cell;
}
- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end

Saturday, 25 January 2014

Simple Form

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Untitled Document</title>
</head>

<body>
<h3 align="center">Top Of Form</h3>
<hr />
Please Complete All Of the following
<form>
<table>
<tr>
    <td width="152">First Name:</td>
    <td colspan="3"><input type="text" name="t1" /></td>
</tr>
<tr>
    <td>Last Name:</td>
    <td colspan="3"><input type="text" name="t2" /></td>
</tr>
<tr>
    <td>Business:</td>
    <td colspan="3"><input type="text" name="t3" /></td>
</tr>
<tr>
    <td height="21"></td>
    <td colspan="2"></td>
</tr>
<tr>
    <td colspan="4">We Must have a correct email address to send you the newsletter</td>
</tr>
<tr>
    <td height="33">Email:</td>
    <td colspan="3"><input type="text" name="t4"  width="200px"/></td>
</tr>
<tr>
    <td height="21" colspan="4"></td>
</tr>
<tr>
    <td colspan="4">How did you here aboout Bigcorp email latter?</td>
</tr>
<tr>
    <td><input type="radio" name="r1" />Here on the Web</td>
    <td width="117"><input type="radio" name="r2" />In a magazine</td>
    <td width="130"><input type="radio" name="r3" />Newspaper story</td>
    <td width="82"><input type="radio" name="r4" />Other</td>
</tr>
<tr>
    <td height="21" colspan="4"></td>
</tr>
<tr>
    <td colspan="4">Would you care to be on our regular mailing list?</td>
</tr>
<tr>
    <td colspan="4"><input type="checkbox" name="c1" />Yes,I love junk mail</td>
</tr>
<tr>
    <td height="21" colspan="4"></td>
</tr>
<tr>
    <td colspan="4">Which are the games you like to play?</td>
</tr>
<tr>
    <td colspan="4">
    <select>
        <option>cricket</option>
        <option>Football</option>
        <option>Basketball</option>
    </select>
    </td>
</tr>
<tr>
    <td colspan="4">Enter the Comment this Website</td>
</tr>
</table>
</form>
<hr />
<h3 align="center">Top Of Form</h3>
</body>
</html>
Untitled Document

Top Of Form


Please Complete All Of the following
First Name:
Last Name:
Business:
We Must have a correct email address to send you the newsletter
Email:
How did you here aboout Bigcorp email latter?
Here on the Web In a magazine Newspaper story Other
Would you care to be on our regular mailing list?
Yes,I love junk mail
Which are the games you like to play?
Enter the Comment this Website

Top Of Form

Telephone Bill Practical

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Untitled Document</title>
</head>

<body>
<h3 align="center">Telephone Bill</h3>
<table width="800px" border="1" align="center">
  <tr>
    <td colspan="2">Subscriber's Name & Address</td>
    <td colspan="2">Consumer No.</td>
    <td colspan="3">P.O.Stamp</td>
  </tr>
  <tr>
    <td colspan="2">Himanshu Patel,New Vadaj,Ahmedabad-13</td>
    <td colspan="2">PL 00515077</td>
    <td width="71"></td>
    <td width="79"></td>
    <td width="137"></td>
  </tr>
  <tr>
    <td width="116">Telephone No</td>
    <td width="109">Type</td>
    <td colspan="2">Bill Date</td>
    <td colspan="2">Dua Date</td>
    <td>Pay By Date</td>
  </tr>
    <tr>
    <td>575007</td>
    <td>GENL RES PERM </td>
    <td colspan="2">1-Aug-97</td>
    <td colspan="2">18-Aug-97</td>
    <td>25-Aug-97</td>
  </tr>
   <tr>
    <td>Opening Meter Reading</td>
    <td>Closing Meter Reading</td>
    <td width="78">Metered Calls</td>
    <td width="54">Debits Calls</td>
    <td>Credits Calls</td>
    <td>Free Calls</td>
    <td>Chargeble Calls</td>
  </tr>
    <tr>
    <td>1052</td>
    <td>1297</td>
    <td width="78">245</td>
    <td width="54">0</td>
    <td>0</td>
    <td>150</td>
    <td>95</td>
  </tr>
  <tr>
      <td colspan="4">Details</td>
    <td>Item</td>
    <td>Period</td>
    <td>Amount</td>
  </tr>
  <tr>
      <td height="46">Rate</td>
    <td>No Of Calls</td>
    <td colspan="2">Charge</td>
    <td>Rent</td>
    <td>10/9/97 to 31/10/97</td>
    <td>200.00</td>
  </tr>
    <tr>
      <td>0.8</td>
    <td>95</td>
    <td colspan="2">76</td>
    <td>Item</td>
    <td>16/5/97 to 15/7/97</td>
    <td>76.00</td>
  </tr>
  <tr>
      <td colspan="2" rowspan="2">Surcharge After Pay Date</td>
    <td colspan="2" rowspan="2">10</td>
    <td>TRP/PG</td>
    <td rowspan="2">16/5/97 to 15/7/97</td>
    <td rowspan="2">0.00</td>
  </tr>
  <tr>
    <td>Calls</td>
  </tr>
  <tr>
      <td colspan="2">Amount on/Before Pay By Date</td>
    <td colspan="2">290</td>
    <td>ITX Calls</td>
    <td>16/5/97 to 15/7/97</td>
    <td>0.00</td>
  </tr>
  <tr>
      <td colspan="2">Amt After Pay By Date</td>
    <td colspan="2">300</td>
    <td>MISC</td>
    <td>TAX</td>
    <td>14.00</td>
  </tr>
  <tr>
      <td colspan="4"></td>
    <td colspan="2">Total</td>
    <td>290.00</td>
  </tr>
   <tr>
      <td colspan="4"></td>
    <td colspan="2">Address</td>
    <td></td>
  </tr>
</table>
</body>
</html>
Untitled Document

Telephone Bill

Subscriber's Name & Address Consumer No. P.O.Stamp
Himanshu Patel,New Vadaj,Ahmedabad-13 PL 00515077
Telephone No Type Bill Date Dua Date Pay By Date
575007 GENL RES PERM 1-Aug-97 18-Aug-97 25-Aug-97
Opening Meter Reading Closing Meter Reading Metered Calls Debits Calls Credits Calls Free Calls Chargeble Calls
1052 1297 245 0 0 150 95
Details Item Period Amount
Rate No Of Calls Charge Rent 10/9/97 to 31/10/97 200.00
0.8 95 76 Item 16/5/97 to 15/7/97 76.00
Surcharge After Pay Date 10 TRP/PG 16/5/97 to 15/7/97 0.00
Calls
Amount on/Before Pay By Date 290 ITX Calls 16/5/97 to 15/7/97 0.00
Amt After Pay By Date 300 MISC TAX 14.00
Total 290.00
Address

Monday, 17 September 2012

Student Registation Data

Untitled Document <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script language="javascript">
var cn=new ActiveXObject("ADODB.Connection");
var str="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\\Himanshu\\Student.mdb";
var rs= new ActiveXObject("ADODB.Recordset");
rs.LockType=3;
function disp()
{
alert("Hi");
var Sql="Select * from stud";
cn.open(str);
rs.open(Sql,cn);
var st = "";
document.getElementById("d1").innerHTML = "";
while(! rs.EOF)
{
document.getElementById("d1").innerHTML += " " + rs(0) + " " + rs(1) + " " + rs(2) + " " + rs(3) +"<br/>";
rs.MoveNext;
}
rs.MoveFirst();
show_data();
}
function show_data()
{
document.f1.t1.value = rs(0);
document.f1.t2.value = rs(1);
document.f1.t3.value = rs(2);
document.f1.t4.value = rs(3);
}
function save_data()
{
rs(0)=document.f1.t1.value;
rs(1)=document.f1.t2.value;
rs(2)=document.f1.t3.value;
rs(3)=document.f1.t4.value;
rs.Update();
alert("Record Saved...");
}
function blank_data()
{
document.f1.t1.value="";
document.f1.t2.value="";
document.f1.t3.value="";
document.f1.t4.value="";
}

function rec_first()
{
rs.MoveFirst();
show_data();
}
function rec_last()
{
rs.MoveLast();
show_data();
}
function rec_prev()
{
rs.MovePrevious();
if(rs.BOF)
{
rs.MoveFirst();
alert("This is first Record")
}
show_data();

}
function rec_next()
{
rs.MoveNext();
if(rs.EOF)
{
rs.MoveLast();
alert("This is last Record");
}
show_data();

}
function rec_add()
{
rs.AddNew();
blank_data();
}
function rec_save()
{
var ptr;
ptr=confirm("Do u want to Save Record?");
if(ptr==true)
{
save_data();

}
Rs.MoveFirst();
show_data();
}
function rec_delete()
{
var ptr;
ptr=confirm("Do u want to delete Record");
if(ptr==true)
{
rs.Delete();
rs.Update();
}
rs.MoveFirst();
show_data();
}
function rec_search()
{
var id=document.f1.t1.value;
rs.MoveFirst();
while(!rs.EOF)
{
if(id==rs(0))
{
show_data();
return;
}
rs.MoveNext();
}
alert("Record Not Found....")
}

</script>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body onload="disp()">
<form name="f1">
<table width="612" border="1px">
<tr>
<td colspan="2"><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="600" height="84">
<param name="movie" value="t.swf" />
<param name="quality" value="high" />
<embed src="t.swf"
quality="high"
type="application/x-shockwave-flash"
width="600"
height="84"
pluginspage="http://www.macromedia.com/go/getflashplayer" />
</object></td>
</tr>
<tr>
<td align="center">Student No</td>
<td align="center"><input type="text"name="t1"/></td>
</tr>
<tr>
<td align="center">Student Name</td>
<td align="center"><input type="text"name="t2"/></td>
</tr>
<tr>
<td align="center">City</td>
<td align="center"><input type="text"name="t3"/></td>
</tr>
<tr>
<td align="center">Pincode</td>
<td align="center"><input type="text"name="t4"/></td>
</tr>
<tr>
<td colspan="2" align="center"><input type="Button" value="First" onclick="rec_first()"/>&nbsp;&nbsp;&nbsp;&nbsp;
<input type="Button" value="Prev" onclick="rec_prev()"/>&nbsp;&nbsp;&nbsp;&nbsp;
<input type="Button" value="Next" onclick="rec_next()"/>&nbsp;&nbsp;&nbsp;&nbsp;
<input type="Button" value="Last" onclick="rec_last()"/></td>
</tr>
<tr>
<td colspan="2" align="center"><input type="Button" value="Add" onclick="rec_add()"/>&nbsp;&nbsp;&nbsp;&nbsp;
<input type="Button" value="Edit"/>&nbsp;&nbsp;&nbsp;&nbsp;
<input type="Button" value="Delete" onclick="rec_delete()"/>&nbsp;&nbsp;&nbsp;&nbsp;
<input type="reset" value="Reset">&nbsp;&nbsp;&nbsp;&nbsp;
<input type="Button" value="Search" onclick="rec_search()"/></td>
</tr>
<tr>
<td colspan="2" align="center"><input type="Button" value="Sava" onclick="rec_save()"/>&nbsp;&nbsp;&nbsp;&nbsp;
<input type="Button" value="Close"/></td>
</tr>
</table>
<div id="d1">Student Info</div>
</form>
</body>
</html>