connectionDidFinishLoading shows an errors in the NSString *jsonString line - iphone

- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
NSError *error = nil;
NSString *jsonString = [[NSJSONSerialization JSONObjectWithData:_buffer options:0 error:&error] description];
dispatch_async(dispatch_get_main_queue(), ^{
if (!error)
{
self.textField.text = jsonString;
}
else
{
self.textField.text = [error localizedDescription];
}
[self.spinner stopAnimating];
[self.fetchButton setEnabled:YES];
self.connection = nil;
self.buffer = nil;
});
});
}
When i write this method then it shows errors in the fifth line. please help me I am new for the Iphone.Thanks in advance.

You should write it like this:
NSString *jsonString = [[NSJSONSerialization JSONObjectWithData:_buffer options:0 error:&error] description];

Remove amp;
from
NSString *jsonString = [[NSJSONSerialization JSONObjectWithData:_buffer options:0 error:&error] description];
It should be
NSString *jsonString = [[NSJSONSerialization JSONObjectWithData:_buffer options:0 error:&error] description];

Related

UITextField and NSURL URLWithString

I have built a translate application in ios. The application uses the Yandex translation api. I followed this tutorial: http://www.raywenderlich.com/5492/working-with-json-in-ios-5
My ViewController.m looks like this (I took out my api key):
#define kBgQueue dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0) //1
#import "ViewController.h"
#end
#interface NSDictionary(JSONCategories)
+(NSDictionary*)dictionaryWithContentsOfJSONURLString:(NSString*)urlAddress;
-(NSData*)toJSON;
#end
#implementation NSDictionary(JSONCategories)
+(NSDictionary*)dictionaryWithContentsOfJSONURLString:(NSString*)urlAddress
{
NSData* data = [NSData dataWithContentsOfURL: [NSURL URLWithString: urlAddress] ];
__autoreleasing NSError* error = nil;
id result = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&error];
if (error != nil) return nil;
return result;
}
-(NSData*)toJSON
{
NSError* error = nil;
id result = [NSJSONSerialization dataWithJSONObject:self options:kNilOptions error:&error];
if (error != nil) return nil;
return result;
}
#end
#implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
dispatch_async(kBgQueue, ^{
// NSData* data = [[NSData dataWithContentsOfURL: TranslateText] ];
NSData*data = [NSURL URLWithString: [NSString stringWithFormat: #"https://translate.yandex.net/api/v1.5/tr.json/translate?key=apikeys&lang=en-es&text=%#", textfield.text]];
[self performSelectorOnMainThread:#selector(fetchedData:) withObject:data waitUntilDone:YES];
});
}
- (void)fetchedData:(NSData *)responseData {
//parse out the json data
NSError* error;
NSDictionary* json = [NSJSONSerialization JSONObjectWithData:responseData //1
options:kNilOptions
error:&error];
NSArray* TranslatedText = [json objectForKey:#"text"]; //2
NSLog(#"Text that was translated: %#", TranslatedText); //3
// 1) Get the latest loan
//NSDictionary* ttext = [TranslatedText objectAtIndex:0];
NSString* ttext = [TranslatedText objectAtIndex:0];
// 3) Set the label appropriately
humanReadble.text = [NSString stringWithFormat:#"%#",
//[ttext objectForKey:#"name"],
ttext];
}
#end`
When I run the app, I get the error Thread 1: signal SIGABRT on this line of code:
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
What should I do?
The error in your code is the use of the colon there. You should have the line be...
[NSURL URLWithString: [NSString stringWithFormat: #"https://translate.yandex.net/api/v1.5/tr.json/translate?apikeyes&text=%#", textfield.text];
Also, I do not know why you would do a #define. Grab the information in the method for handling the button getting pressed.
NSURL * translateURL = [NSURL URLWithString: [NSString stringWithFormat: #"https://translate.yandex.net/api/v1.5/tr.json/translate?apikeyes&text=%#", textfield.text];

Load Web-Content Asynchronously

I am trying to load web content asynchronously. I have a large amount of web calls in my viewdidappear method and my app is very unresponsive. I understand the concepts of synchronous and asynchronous loading of content, but don't know how to tell if this is being done asynchronously. The code below is simply embedded in my viewdidappear method, and I assume it is loading synchronously. How would I edit this to make it load asynchronously? Thank you all!
NSString *strURLtwo = [NSString stringWithFormat:#"http://website.com/json.php?
id=%#&lat1=%#&lon1=%#",id, lat, lon];
NSData *dataURLtwo = [NSData dataWithContentsOfURL:[NSURL URLWithString:strURLtwo]];
NSArray *readJsonArray = [NSJSONSerialization JSONObjectWithData:dataURLtwo options:0
error:nil];
NSDictionary *element1 = [readJsonArray objectAtIndex:0];
NSString *name = [element1 objectForKey:#"name"];
NSString *address = [element1 objectForKey:#"address"];
NSString *phone = [element1 objectForKey:#"phone"];
You can use NSURLConnectionDelegate:
// Your public fetch method
-(void)fetchData
{
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:#"http://website.com/json.php?id=%#&lat1=%#&lon1=%#",id, lat, lon]];
// Put that URL into an NSURLRequest
NSMutableURLRequest *req = [NSMutableURLRequest requestWithURL:url];
// Create a connection that will exchange this request for data from the URL
connection = [[NSURLConnection alloc] initWithRequest:req
delegate:self
startImmediately:YES];
}
Implement the delegate methods:
- (void)connection:(NSURLConnection *)conn didReceiveData:(NSData *)data
{
// Add the incoming chunk of data to the container we are keeping
// The data always comes in the correct order
[jsonData appendData:data];
}
- (void)connectionDidFinishLoading:(NSURLConnection *)conn
{
// All data is downloaded. Do your stuff with the data
NSArray *readJsonArray = [NSJSONSerialization jsonData options:0 error:nil];
NSDictionary *element1 = [readJsonArray objectAtIndex:0];
NSString *name = [element1 objectForKey:#"name"];
NSString *address = [element1 objectForKey:#"address"];
NSString *phone = [element1 objectForKey:#"phone"];
jsonData = nil;
connection = nil;
}
// Show AlertView if error
- (void)connection:(NSURLConnection *)conn didFailWithError:(NSError *)error
{
connection = nil;
jsonData = nil;
NSString *errorString = [NSString stringWithFormat:#"Fetch failed: %#", [error localizedDescription]];
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:#"Error" message:errorString delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil, nil];
[alertView show];
}
For asynchronous web content loading, I recommend you to use AFNetworking . It'll solve lots of your major headache of networking in future. How to do:
1) subclass AFHTTPCLient, for example:
//WebClientHelper.h
#import "AFHTTPClient.h"
#interface WebClientHelper : AFHTTPClient{
}
+(WebClientHelper *)sharedClient;
#end
//WebClientHelper.m
#import "WebClientHelper.h"
#import "AFHTTPRequestOperation.h"
NSString *const gWebBaseURL = #"http://whateverBaseURL.com/";
#implementation WebClientHelper
+(WebClientHelper *)sharedClient
{
static WebClientHelper * _sharedClient = nil;
static dispatch_once_t oncePredicate;
dispatch_once(&oncePredicate, ^{
_sharedClient = [[self alloc] initWithBaseURL:[NSURL URLWithString:gWebBaseURL]];
});
return _sharedClient;
}
- (id)initWithBaseURL:(NSURL *)url
{
self = [super initWithBaseURL:url];
if (!self) {
return nil;
}
[self registerHTTPOperationClass:[AFHTTPRequestOperation class]];
return self;
}
#end
2) Request asynchronously your web content, put this code in any relevant part
NSString *testNewsURL = #"http://whatever.com";
NSURL *url = [NSURL URLWithString:testNewsURL];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
AFHTTPRequestOperation *operationHttp =
[[WebClientHelper sharedClient] HTTPRequestOperationWithRequest:request success:^(AFHTTPRequestOperation *operation, id responseObject)
{
NSString *szResponse = [[[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding] autorelease];
NSLog(#"Response: %#", szResponse );
//PUT your code here
}
failure:^(AFHTTPRequestOperation *operation, NSError *error)
{
NSLog(#"Operation Error: %#", error.localizedDescription);
}];
[[WebClientHelper sharedClient] enqueueHTTPRequestOperation:operationHttp];

Parse JSON - iPhone

I'm new with json, and I need your help please.
I received JSON string like this :
{"network":
{
"network_id":111,
"name":"test name",
"city":"test city",
"country":"test country",
"description":"test desc"
}
}
How I can handle this string and split key/value in order to use them in my view ?
- (void) connectionDidFinishLoading:(NSURLConnection *)connection {
[connection release];
NSString *responseString = [[NSString alloc] initWithData:self.responseData encoding:NSUTF8StringEncoding];
self.responseData = nil;
//*********** How I can parse responseString *********//
[networkIDLabel setText:#"ADD THE VALUE"];
[nameLabel setText:#"ADD THE VALUE"];
[responseString release];
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
}
thanks
In iOS 5 and later, you can parse the response data directly with NSJSONSerialization:
[NSJSONSerialization JSONObjectWithData:self.responseData …];
If you want to support earlier versions of iOS, you can use JSONKit.
In objective-c json can be represnted as Dictionary
-(void)getData:(NSData*)response{
// You have to include the SBJSON or else you can also use the NSJSONSerialization
//NSDictionary *jsonData = [NSJSONSerialization JSONObjectWithData:response options:kNilOptions error:&erro];
SBJSON *parse = [[SBJSON alloc]init];
NSString *jsonString = [[NSString alloc] initWithData:response
encoding:NSUTF8StringEncoding];
NSDictionary *jsonData = [parse objectWithString:jsonString error:&erro];
NSDictionary *insideData = [jsonData objectForKey:#"network"];
if(![insideData isKindOfClass:[NSNull class]])
{
NSString *data1 = [insideData objectForKey:#"network_Id"];
NSString *data2 = [insideData objectForKey:#"name"];
}
}

how can i parse a json string into nsdictionary?

i am writing code for login application. can anyone help me how to parse a json string?
my code is
-(void)connectionDidFinishLoading:(NSURLConnection *)connection
{
NSString *loginStatus = [[NSString alloc] initWithBytes: [webData mutableBytes] length:[webData length] encoding:NSUTF8StringEncoding];
SBJsonParser *parser = [[SBJsonParser alloc] init];
NSArray *loginDict = [parser objectWithString:loginDict error:nil];
[loginStatus release];
[connection release];
Example data:
NSString *strData = #"{\"1\": {\"name\": \"Jerry\",\"age\": \"12\"}, \"2\": {\"name\": \"Bob\",\"age\": \"16\"}}";
NSData *webData = [strData dataUsingEncoding:NSUTF8StringEncoding];
NSError *error;
NSDictionary *jsonDict = [NSJSONSerialization JSONObjectWithData:webData options:0 error:&error];
NSLog(#"JSON DIct: %#", jsonDict);
NSLog output:
JSON DIct: {
1 = {
age = 12;
name = Jerry;
};
2 = {
age = 16;
name = Bob;
};
}
//*************Static Resopnse
NSString *filePath = [[NSBundle mainBundle] pathForResource:#"demo" ofType:#"text"];
NSLog (#"Content: %#", filePath);
NSString *content = [[[NSString alloc] initWithContentsOfFile:filePath
usedEncoding:nil
error:nil] autorelease];
SBJSON *json = [[SBJSON new] autorelease];
NSString *str=[[NSString alloc]initWithString:content];
dictTemp = [json objectWithString:str error:nil];
NSLog(#"Actions is: %#",dictTemp);
NSArray *arr=[[dictTemp valueForKey:#"Data"] mutableCopy];
arrX=[[NSMutableArray alloc] init];
arrY=[[NSMutableArray alloc] init];
for(NSDictionary *dict in arr)
{
[arrX addObject:[dict valueForKey:#"Milestone"]];
[arrY addObject:[dict valueForKey:#"Sites"]];
}
NSLog(#"X is: %#",[arrX description]);
NSLog(#"Y is: %#",[arrY description]);
NSString *loginStatus = [[NSString alloc] initWithBytes: [webData mutableBytes] length:[webData length] encoding:NSUTF8StringEncoding]
NSLog([[loginStatus JSONValue] description],nil);
//This will give you parsed output.
NSString *responseString = [[NSString alloc] initWithData:responseData encoding: NSASCIIStringEncoding];
NSlog(#"json String is: %#",responseString);
NSDictionary *dictionary = [responseString JSONValue];
NSLog(#"Dictionary value is %#", [dictionary objectForKey:#"json"]);
the result of this code is:json String is: {"json":{"Success":"Activation code."}}
After Conversation the result is ------- Dictionary value is {
Success = "Activation code."};

Objective C alloc/release error

I have the following problem:
in header;
GDataXMLDocument *doc;
NSString *xmlBody;
#property (nonatomic,copy) NSString *xmlBody;
#property (nonatomic,retain) GDataXMLDocument *doc;
in m
#import "tchLoader.h"
#import "Variable.h"
#import "DisplayVariable.h"
#implementation tchLoader
#synthesize responseXMLData,lastLoadedResponseXMLData;
#synthesize conn;
#synthesize doc;
#synthesize xmlBody;
- (void)loadXML:(id<tchLoaderDelegate>)delegate {
NSString *theBaseXML= #"some xml code here"
if (self.xmlBody==nil){
self.xmlBody=theBaseXML;
}
_delegate = delegate;
/*
SCNetworkReachabilityFlags flags;
SCNetworkReachabilityRef reachability = SCNetworkReachabilityCreateWithName(NULL, [#"www.alues.com" UTF8String]);
SCNetworkReachabilityGetFlags(reachability, &flags);
// The reachability flags are a bitwise set of flags that contain the information about
// connection availability
BOOL reachable = ! (flags & kSCNetworkReachabilityFlagsConnectionRequired);
*/
NSString *soapMessage =self.xmlBody;
NSURL *url = [NSURL URLWithString:#"https://area.tch-values.com/soapmwp/mws"];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
NSString *msgLength = [NSString stringWithFormat:#"%d", [soapMessage length]];
[request addValue: #"text/xml; charset=utf-8" forHTTPHeaderField:#"Content-Type"];
[request addValue: #"http://www.tch-values.com/webservice" forHTTPHeaderField:#"SOAPAction"];
[request addValue: msgLength forHTTPHeaderField:#"Content-Length"];
[request setHTTPMethod:#"POST"];
[request setHTTPBody: [soapMessage dataUsingEncoding:NSUTF8StringEncoding]];
if ([NSURLConnection canHandleRequest:request] && true) {
self.conn = [[NSURLConnection alloc ]initWithRequest:request delegate:self];
if (self.conn) {
self.responseXMLData = [NSMutableData data];
}
}
}
-(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
{
NSLog(#"ERROR with theConenction");
[self.doc release];
[self.conn release];
[self.responseXMLData release];
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
NSLog(#"DONE. Received Bytes: %d", [self.responseXMLData length]);
//[self.conn release];
if ([_delegate respondsToSelector:#selector(xmlDidFinishLoading)]) {
[_delegate xmlDidFinishLoading];
}
}
-(void)insertAnswers: (NSMutableArray*) answeredVariables{
for (Variable * variable in answeredVariables)
{
NSInteger pageID=[variable pageId];
//NSMutableArray *answers=[NSMutableArray arrayWithCapacity:[[variable variableValues] count]];
NSString *path = [NSString stringWithFormat:#"//inferenceresponse/state/variable[pageId=%d]/valuedefinition",pageID];
NSArray *valueElement = [doc nodesForXPath:path error:nil];
GDataXMLElement *valueDefinitionElement;
if (valueElement.count > 0) {
valueDefinitionElement= (GDataXMLElement *) [valueElement objectAtIndex:0];
}
GDataXMLElement * sourceElement = [GDataXMLNode elementWithName:#"source"];
[sourceElement addAttribute:[GDataXMLNode attributeWithName:#"type" stringValue:#"ask user"]];
GDataXMLElement * timeStampElement = [GDataXMLNode elementWithName:#"timestamp" stringValue:#"12345"];
[sourceElement addChild:timeStampElement];
GDataXMLElement * assignmentElement = [GDataXMLNode elementWithName:#"assignmentnumber" stringValue:#"6"];
for(NSString *answer in variable.variableValues){
GDataXMLElement * variableValueElement = [GDataXMLNode elementWithName:#"variablevalue"];
[variableValueElement addAttribute:[GDataXMLNode attributeWithName:#"value" stringValue:answer]];
[valueDefinitionElement addChild:variableValueElement];
}
[valueDefinitionElement addChild:sourceElement];
[valueDefinitionElement addChild:assignmentElement];
}
NSData *xmlData = self.doc.XMLData;
NSString *theXML = [[NSString alloc] initWithBytes:[xmlData bytes] length:[xmlData length] encoding:NSUTF8StringEncoding];
theXML =[theXML stringByReplacingOccurrencesOfString:#"inferenceresponse" withString:#"inferencerequest"];
theXML =[theXML stringByReplacingOccurrencesOfString:#"<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\">" withString:#"<SOAP-ENV:Envelope xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:SOAP-ENC=\"http://schemas.xmlsoap.org/soap/encoding/\" SOAP-ENV:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\"> "];
theXML =[theXML stringByReplacingOccurrencesOfString:#"xmlns=\"\"" withString:#"xmlns=\"http://www.tch-values.com/xml/webservice\""];
theXML =[theXML stringByReplacingOccurrencesOfString:#"<state goalreached=\"false\">" withString:#"<state goalreached=\"false\"> <value>PlanKB</value> <goalvariable>myGoal</goalvariable> "];
self.xmlBody=theXML;
[theXML release];
//[self.doc release];
NSLog(self.xmlBody);
}
- (NSMutableArray*)variablesForPageID:(NSString*)pageID {
NSMutableArray *variables = nil;
if (self.responseXMLData) {
variables = [NSMutableArray arrayWithCapacity:10];
NSData *xmlData = self.responseXMLData;
NSError *error;
self.doc=nil;
doc = [[GDataXMLDocument alloc] initWithData:xmlData options:0 error:&error];
if (self.doc == nil) {
return nil;
}
NSArray *status = [doc nodesForXPath:#"//inferenceresponse/state[#goalreached='true']" error:nil];
if([status count]==1){
self.xmlBody=nil;
Variable *variable=[[Variable alloc] init];
NSString *path = [NSString stringWithFormat:#"//inferenceresponse/state/displayvariables/display[#isDisplayShown='false']"];
NSArray *displayVariablesElements = [doc nodesForXPath:path error:nil];
NSMutableArray *disps=[[NSMutableArray alloc] init];
if(displayVariablesElements.count >0){
for(GDataXMLElement *disElement in displayVariablesElements){
DisplayVariable *disVar=[[DisplayVariable alloc] init];
NSArray *disPageid = [disElement nodesForXPath:#"#displayPageId" error:nil];
GDataXMLElement *Pageid = (GDataXMLElement *) [disPageid objectAtIndex:0];
disVar.displayPageId =Pageid.stringValue;
NSArray *disName = [disElement nodesForXPath:#"displayname" error:nil];
if(disName.count >0){
GDataXMLElement *disNam = (GDataXMLElement *) [disName objectAtIndex:0];
disVar.displayName =disNam.stringValue;
}
NSArray *disValue = [disElement nodesForXPath:#"displayvalue" error:nil];
if(disValue.count >0){
GDataXMLElement *disVal = (GDataXMLElement *) [disValue objectAtIndex:0];
disVar.displayValue =disVal.stringValue;
}
NSArray *disId = [disElement nodesForXPath:#"#id" error:nil];
GDataXMLElement *disIdEl = (GDataXMLElement *) [disId objectAtIndex:0];
disVar.pageId =[disIdEl.stringValue intValue];
[disps addObject:disVar];
[disVar release];
}
variable.displayVariables=disps;
[disps release];
}
variable.lastVariableofConsultation=YES;
[variables addObject:variable];
[variable release];
}
else{
NSArray *inferenceMembers = [doc nodesForXPath:#"//inferenceresponse/state/variable[not(valuedefinition/variablevalue)]" error:nil];
for (GDataXMLElement *variableElement in inferenceMembers) {
Variable *variable=[[Variable alloc] init];
NSArray *items = [variableElement nodesForXPath:#"domaindefinition/domain/enumType/domainitem" error:nil];
NSMutableArray *domainItems = [NSMutableArray arrayWithCapacity:items.count];
for (int i=0; i<items.count;i++) {
GDataXMLElement *domainItem = (GDataXMLElement *) [items objectAtIndex:i];
[domainItems addObject:domainItem.stringValue];
}
variable.domainItems=domainItems;
NSArray *names = [variableElement nodesForXPath:#"name/#name" error:nil];
if (names.count > 0) {
GDataXMLElement *nameElement = (GDataXMLElement *) [names objectAtIndex:0];
variable.variableName = nameElement.stringValue;
}
NSArray *pageId = [variableElement nodesForXPath:#"pageId" error:nil];
}
}
return variables;
}
- (void)dealloc {
[responseXMLData release] ;
[lastLoadedResponseXMLData release] ;
[conn release];
[doc release];
[xmlBody release];
[super dealloc];
}
#end
#import "tchLoader.h"
#import "Variable.h"
#import "DisplayVariable.h"
#implementation tchLoader
#synthesize responseXMLData,lastLoadedResponseXMLData;
#synthesize conn;
#synthesize doc;
#synthesize xmlBody;
If I [theXML release] it crashes, If I dont release theXML then it works perfect but I see memory leak in simulator Instruments tool. (There are also lots of memory leaks I see in this code but couldnt figure out by instrumnets tool what is going on)
This looks wrong:
[doc release];
Why are you releasing an object managed by a property?
In your #synthesize statements change them to:
#synthesize doc = doc_;
#synthesize xmlBody = xmlBody_;
Then fix all the resulting errors to go through the property, releasing the properties ONLY in dealloc.
Edit:
You say it crashes releasing theXML. This code is wrong:
NSString *theXML = [[NSString alloc] initWithBytes:[xmlData bytes] length:[xmlData length] encoding:NSUTF8StringEncoding];  
        theXML =[theXML stringByReplacingOccurrencesOfString:#"inferenceresponse" withString:#"inferencerequest"];
[theXML release];
You alloc a string, replace that variable with the "stringByReplacing..." call with a string that is autoreleased, then try to release the resulting string that is autoreleased which will crash. When you don't need to keep a string around after the method you are in, ALWAYS use autorelease. The correct code is:
NSString *theXML = [[[NSString alloc] initWithBytes:[xmlData bytes] length:[xmlData length] encoding:NSUTF8StringEncoding] autorelease];  
        theXML =[theXML stringByReplacingOccurrencesOfString:#"inferenceresponse" withString:#"inferencerequest"];
And take out [theXML release] - there will be no leak.
I think you should really switch to using ARC as soon as you possibly can... it will save you from a lot of such misunderstandings.
If you want to release an ivar/property(retain), this is not how to to it:
[self.doc release];
instead:
self.doc = nil;
One "problem" with singleton objects is that they appear to leak. If you create an object and never destroy it, Instruments says it's a leak, even if your intention was never to release it.
NSData *xmlData = doc.XMLData;
newXML = [[NSString alloc] initWithBytes:[xmlData bytes] length:[xmlData length]
encoding:NSUTF8StringEncoding];
What is your newXML? is it a ivar and synthesize it and retain it? if yes the compiler will automatically generate getter and setter methods.
NSData *xmlData = doc.XMLData;
self.newXML = [[NSString alloc] initWithBytes:[xmlData bytes] length:[xmlData length]
encoding:NSUTF8StringEncoding];
self.timestamp = nil;
If its not property then
NSString* newXML = [[NSString alloc] initWithBytes:[xmlData bytes] length:[xmlData length]
encoding:NSUTF8StringEncoding];
self.xmlBody=newXML;
[newXML release];