views:

24

answers:

1

Hello,

I am new to objective c. I am right now working on the web service based application.I am using .net webservice that i would like to point out.

The thing is that using XML code,i am able to fetch the XML string in a simple string variable,but i cant get how to get data from the same in different variable.

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt;
  <soap:Body>
    <GetDetailResponse xmlns="http://tempuri.org/"&gt;
      <GetDetailResult>{"TimeRemaining":"0 days 0 Hrs 0Mins","Rank":"0","Marks":"0","ContractsHeld":"0","CurrentLocation":"London","CurrentLatitude":23.056989,"CurrentLongitude":72.565384}</GetDetailResult>
    </GetDetailResponse>
  </soap:Body>
</soap:Envelope>

The above given is my xml string,that i am able to fetch in a string.now if i want to say fetch data of say CurrentLongitude in some variable,what should i do?

I tried the code :

- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI 
      qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict
    { 
     currElement = [elementName copy];

     if ([elementName isEqualToString:@"Location"]) 
     {
      txt1.text = [[NSMutableString alloc]init];
     }
     else if([elementName isEqualToString:@"TimeRemaining"])
     {
      txt1.text = [[NSMutableString alloc]init]; 
     }
    }

but it results into "soap:Envelope" variable elementName.How should i fetch CurrentLocation or some other variable?

Kindly help me out.

Thank you.

A: 

JSON within XML? You could extract the JSON and then put that into a JSON parser for Cocoa. But you'd prob be better off to put in the work to format the JSON as XML and use the built in parser or Xpath.

sciritai
Well I think i am much more nearer to the solution with the XML parsing,now to go with the option of JSON will take much time of mine,so better i go with this only. Can't you give solution pertaining to XML parsing itself?