going to fetch a value from xml response when going to parse but i am fail to get value
-
18-04-2021 - |
سؤال
Below code is the response from the server:
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><SendCardDetailsResponse xmlns="http://tempuri.org/"><SendCardDetailsResult><ROOT xmlns=""><DocumentElement><res-auth><auth-data count='1' ><**attribute name='OTP1'** length='6' type='N' label='OTP' prompt='Please enter OTP as send to your mobile.'/></auth-data></res-auth></DocumentElement></ROOT></SendCardDetailsResult></SendCardDetailsResponse></soap:Body></soap:Envelope>
I have to fetch attribute name which is 'OTP1' how can I get value of attribute name any help will be appreciable
المحلول
I would use smth like this:
-(NSString*) getAttribute{
NSString *attribute = @"";
NSString *xmlString = @"";//put the XML in this NSString
int endOfSrc = [xmlString rangeOfString:@"\"><attribute name='"].location+[xmlString rangeOfString:@"\"><attribute name='"].length;
int borderPos = [xmlString rangeOfString:@"' length='"].location;
if(borderPos != NSNotFound){
NSRange range;
range.location = endOfSrc;
range.length = borderPos - endOfSrc;
attribute = [xmlString substringWithRange:range];
return attribute;
}
return @" ";
}
Nothing hard here, if some questions about the code appear, just see the documentation for the functions i've used here. maybe there are more efficient ways, dunno. It works like a charm for me.
لا تنتمي إلى StackOverflow