【问题标题】:Parsing NSXMLElement in ios7在 ios7 中解析 NSXMLElement
【发布时间】:2014-05-14 04:04:58
【问题描述】:

我有

 "<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”属性的值。我用

         NSArray * children =  [queryElements children];
            NSArray *  attributes = [queryElements attributes];
            NSXMLElement *qq = children[1];

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

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

然后得到 (null)。

我得到了这个

                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

还有更聪明的方法吗?

【问题讨论】:

    标签: xml web-services nsxmlparser nsxml nsxmlelement


    【解决方案1】:

    如果你想要数组中的所有属性,你可以这样使用:

    for (NSXMLElement * childrenElement in children) {
        NSString *id = [[childrenElement attributeForName:@"id"]stringValue];
        NSLog(@"print childrenElement id=====%@",id);        
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-02-10
      • 2012-06-03
      • 2012-11-27
      • 2015-11-13
      • 2012-04-25
      相关资源
      最近更新 更多