1

i am trying to parse an xml file that i receive from a web service using the tutorial Soap Tutorial

..

i initialize the data received to a NSString as follows

NSString *theXML = [[NSString alloc] 
                        initWithBytes: [webData mutableBytes] 
                        length:[webData length] 
                        encoding:NSUTF8StringEncoding];

`

    <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body>
<GetCategoryResponse xmlns="http://tempuri.org/">
<GetCategoryResult>
<Root><Record><catid>1</catid><catname>Hi</catname><catlogo>http://10.25.4.49/monsoonstore/Category/50X50.GIF</catlogo></Record></Root></GetCategoryResult>
</GetCategoryResponse>
</s:Body>
</s:Envelope>

when i parse the data my parser doesn't read the ROOT tag as it should but instead starts with the envelope tag.. how can i get the parser to parse the exact xml that i receive from the server i.e

<Root><Record><catid>1</catid><catname>Hi</catname><catlogo>http://10.25.4.49/monsoonstore/Category/50X50.GIF</catlogo></Record></Root>

how can i parse this webData with te correct tags??

abhishek kumar
  • 95
  • 2
  • 11
  • If posible so just give me the url from where u getting this xml data i'll try my own and after that i'll give you the solution. – user755278 Jun 03 '11 at 06:55
  • http://10.25.4.49/MonSoonStore/ClientService.svc web service link http://tempuri.org/IClientService/GetCategory" is the@"SOAPAction" – abhishek kumar Jun 03 '11 at 07:50
  • To parse XML in iPhone, you need to use NSXMLParser. [NSXMLParser Class reference](http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSXMLParser_Class/Reference/Reference.html) – Swapna Jun 03 '11 at 06:46
  • Please go through following link, you will get better idea, 1)kosmaczewski.net 2)http://icodeblog.com/2008/11/03/iphone-programming-tutorial-intro-to-soap-web-services/ 3)http://viium.com 4)http://blog.exadel.com/working-with-ios-and-soap/ – Tirth Jun 03 '11 at 06:29

1 Answers1

1

you may use the TouchXML parser to get better and desired results, and then use in XML parser function

NSString *responseString = [[[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding] autorelease];
CXMLDocument *xmlParser = [[[CXMLDocument alloc] initWithXMLString:responseString options:0 error:nil] autorelease];
NSArray *returnNodes = NULL;
returnNodes = [xmlParser nodesForXPath:@"//Root" error:nil];
.
.
.