首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在ios7中解析NSXMLElement

在ios7中解析NSXMLElement
EN

Stack Overflow用户
提问于 2014-04-03 01:31:33
回答 1查看 260关注 0票数 0

我有过

代码语言:javascript
复制
 "<message xmlns=\"jabber:client\" type=\"chat\" to=\"3@.com\" from=\"4@.com/44b97a48-f761-4332-a7a6-734e8e3d81f2\" id=\"168AA10F-B3B1-430B-9EDF-2A6126161CF5\" timestamp=\"2014-03-29 01:23:16 +0000\"><body>Yt itygvgy glkbhlkblkblkblblibibilub</body><request xmlns=\"urn:xmpp:receipts\"></request></message>"

我需要获取“to”属性的值。我使用

代码语言:javascript
复制
         NSArray * children =  [queryElements children];
            NSArray *  attributes = [queryElements attributes];
            NSXMLElement *qq = children[1];

            NSXMLElement *resultElements = [qq elementForName: @"to" xmlns: @"jabber:client"];

            NSLog(@"TWST :\n%@", resultElements);

和get (null)。

我是这样得到的

代码语言:javascript
复制
                NSArray * children =  [queryElements children];
           NSLog(@"children:\n%@ :\n", children);
            NSXMLElement *qq = children[1];
            NSArray * children2 =  [qq children];
            NSLog(@"22:\n%@ :\n", children2[0]); //body
            NSArray * children333 =  [qq attributes];
            NSLog(@"3333:\n%@ :\n", children333[2]); //from

有没有更聪明的方法?

EN

回答 1

Stack Overflow用户

发布于 2015-03-16 20:38:45

如果您想要数组中的所有属性,您可以使用以下方式:

代码语言:javascript
复制
for (NSXMLElement * childrenElement in children) {
    NSString *id = [[childrenElement attributeForName:@"id"]stringValue];
    NSLog(@"print childrenElement id=====%@",id);        
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22818802

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档