解析时将从 xml 响应中获取值,但我无法获取值

发布于 2024-12-28 09:51:07 字数 680 浏览 2 评论 0原文

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

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” 如何获取属性名称的值 任何帮助都会很明显

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

把梦留给海 2025-01-04 09:51:07

我会这样使用:

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

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

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文