1

下面的代码是来自服务器的响应:

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>

我必须获取“OTP1”的属性名称我怎样才能获得属性名称的值任何帮助都会很明显

4

1 回答 1

0

我会这样使用:

-(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 @" ";
}

这里没什么难的,如果出现关于代码的一些问题,只需查看我在这里使用的函数的文档即可。也许有更有效的方法,不知道。它对我来说就像一个魅力。

于 2012-01-20T09:27:41.183 回答