如何在ios中parsingxmpp xml?

您好我正在与xmpp工作正常的每一件事情,但我无法parsing下面的XML

<message xmlns="jabber:client" to="919452544@server" id="859e7-870" type="chat" from="917696997127@server/Smack"> <body>Broadcast</body> <properties xmlns="http://www.jivesoftware.com/xmlns/xmpp/properties"> <property> <name>stream</name> <value type="string">8d879bea44f792468d6ecad161d3e545</value> </property> <property> <name>date</name> <value type="string">2016-05-05 10:36:25</value> </property> <property> <name>broadcast</name> <value type="string">Broadcast</value> </property> </properties> </message> 

在上面的XML首先我需要检查身体是否等于广播。 然后我需要parsing<name>stream</name><value type="string">8d879bea44f792468d6ecad161d3e545</value>如何在上面的xml中获取名称和值。 我试过这样,但每次都是成功的。下面是我的代码

  if ([message elementsForName:@"name"] ) { NSArray *nameArray=[message elementsForName:@"name"]; NSLog(@"name Broadcast %@",nameArray); } 

但nameArray总是empty.please帮助我

试试这个… <name>stream</name>是数组元素, <property>... <\property>是NSArray

 NSXMLElement *properties = [message elementForName:@"properties"]; NSArray *property = [properties elementsForName:@"property"]; NSLog(@"property: %@", property); //loop to get name and value for (NSXMLElement *i in property) { NSXMLElement *name = [i elementForName:@"name"]; NSString *n = [name stringValue]; NSLog(@"name: %@", n); // like wise you can get value }