views:

73

answers:

3

Hi all,

i m using this code for posting and getting the data from the server.

NSString *post =[NSString stringWithFormat:@"any-data=%@", myData];

NSData *postData = [post dataUsingEncoding:NSUTF8StringEncoding allowLossyConversion:YES];

NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];

NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease];
[request setURL:[NSURL URLWithString:@"http://your-server.com/your-script.php"]];
[request setHTTPMethod:@"POST"];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody:postData];

NSURLResponse *response;
NSData *urlData=[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
NSString *data=[[NSString alloc]initWithData:urlData encoding:NSUTF8StringEncoding];
NSLog(@"Data: %@",data);

but problem is that when i print data in nslog then it is in html formate how i retrieve actual result in my application.

how parse data?

please give me if any refrence.

+3  A: 

You could always try searching 1. Around Stack Overflow, and 2. Google.

Unfortunately attempting this is not going to be easy unless you can guarantee well formed XHTML. If your XHTML is indeed guaranteed to be valid then you could use XSXMLParser. You could also check out the HTMLParser.h code in libxml/HTMLparser.h which is provided by libxml2, in which this link may help you.

I've noticed that a lot of applications use basic String splitting for data extraction.

injekt
i search this on google as well as stackoverflow but i m not find any exact soln so i ask,i use libxml2 but in this code it requires html file but i have php file so how i implement with HTMLparser.
Arun Sharma
If you can provide some input, some desired output, and the code you're currently using to extract this information. It may help people give you advice.
injekt
+1  A: 

If you're just scraping the HTML for data, NSScanner will do. If you want to display the data, a UIWebView will work. It depends on what you want to do with the HTML. You don't need an XML parser — in most cases that's overkill.

lucius
Thanks i m using nsscanner...
Arun Sharma
A: 

If you're feeling bold and you know what to extract from your document, have a look at RegexKit Lite. Obviously, you'll have to come up with the proper regular expression that matches exactly what you're searching for and captures the content you're interested in.

Benjamin