生成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];

}

相关文章

php输出xml格式字符串
J2ME Mobile 3D入门教程系列文章之一
XML轻松学习手册
XML入门的常见问题(一)
XML入门的常见问题(三)
XML轻松学习手册(2)XML概念