user3486428
user3486428

Reputation: 33

Parsing NSXMLElement in ios7

I have

 "<message xmlns=\"jabber:client\" type=\"chat\" to=\"[email protected]\" from=\"[email protected]/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>"

I need get value of 'to' attribute. I use

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

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

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

And get (null).

I get this with

                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

Is there more clever way?

Upvotes: 0

Views: 272

Answers (1)

TMD
TMD

Reputation: 380

if you want all attributes from array, You can use this way:

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

Upvotes: 1

Related Questions