生成xml数据

来源:互联网 发布:森田药妆面膜 知乎 编辑:程序博客网 时间:2024/05/18 09:18

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


/**

 *  发送消息

 */

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

{

    //创建一个xml

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

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

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

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

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

    [body setStringValue:_msg];

    [message addChild:body];

    NSLog(@"%@",message);

    

    [xmppStreamsendElement:message];

}

0 0
原创粉丝点击