Knowledge Base Nr: 00342 getxmlxcode.m - http://www.swe-kaiser.de

Downloads:

ObjC: get xml tag from string

  
- (NSString*)getXMLTag:(NSString*)sXML tag:(NSString*)sTag
{
NSString* sStart = [[NSString alloc] initWithFormat:@"<%@>", sTag];
NSString* sEnd = [[NSString alloc] initWithFormat:@"</%@>", sTag];

NSMutableArray* arr = [[NSMutableArray alloc] initWithArray:[sXML componentsSeparatedByString:sStart]];
if ([arr count] < 2)
return @"";

NSString* sContent = (NSString*)[arr objectAtIndex:1];
arr = [[NSMutableArray alloc] initWithArray:[sContent componentsSeparatedByString:sEnd]];
if ([arr count] < 2)
return @"";

sContent = (NSString*)[arr objectAtIndex:0];
return sContent;
}