生成xml数据

前端之家收集整理的这篇文章主要介绍了生成xml数据前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

<message type="chat" to="zhq1@localhost" from="123@localhost"><body>hhhh</body></message>


/**

* 发送消息

*/

- (void)sendMessage:(NSString *)_msg to:(NSString *)_to

{

//创建一个xml

NSXMLElement *message = [NSXMLElement elementWithName:@"message"];

[message addAttributeWithName:@"type" stringValue:@"chat"];

[message addAttributeWithName:@"to" stringValue:[NSString stringWithFormat:@"%@@localhost",_to]];

[message addAttributeWithName:@"from" stringValue:[NSString stringWithFormat:@"123@localhost"]];

NSXMLElement *body = [NSXMLElement elementWithName:@"body"];

[body setStringValue:_msg];

[message addChild:body];

NSLog(@"%@",message);

[xmppStream sendElement:message];

}

猜你在找的XML相关文章