objective c - XMPP: How to parse XMPPMessage element -


i'm getting following xml format every message coming xmpp

- (void)xmppstream:(xmppstream *)sender didreceivemessage:(xmppmessage *)message {  nslog(@"message %@",message);         } 

in console printing

<message     xmlns="jabber:client" from="10000006956@xmpp-dev.peeks.com" to="10000006956@xmpp-dev.peeks.com/mobile">     <result         xmlns="urn:xmpp:mam:tmp" id="1483781596098940">         <forwarded             xmlns="urn:xmpp:forward:0">             <message                 xmlns="jabber:client" from="10000006931@xmpp-dev.peeks.com/mobile" to="10000006956@xmpp-dev.peeks.com" type="chat">                 <body>hi</body>                 <delay                     xmlns="urn:xmpp:delay" from="xmpp-dev.peeks.com" stamp="2016-12-22t04:50:17.023z">offline storage                 </delay>             </message>             <delay                 xmlns="urn:xmpp:delay" from="xmpp-dev.peeks.com" stamp="2017-01-07t09:33:16.099z">             </delay>         </forwarded>     </result> </message> 

i want fetch "from", "to", "body", , "stamp" every message , did following

nsxmlelement *body = message;     nsxmlelement *messageb  = [body elementforname:@"result" xmlns:@"urn:xmpp:mam:tmp"];     nsxmlelement *forwa=[messageb elementforname:@"forwarded" xmlns:@"urn:xmpp:forward:0"];     nsxmlelement *msg=[forwa elementforname:@"message" xmlns:@"jabber:client"];     nsxmlelement *td=[forwa elementforname:@"delay" xmlns:@"urn:xmpp:delay"];      nsstring *from=[[msg elementforname:@"from" xmlns:@"jabber:client"] stringvalue];     nsstring *to=[[msg elementforname:@"to" xmlns:@"jabber:client"] stringvalue];     nsstring *bodyq=[[msg elementforname:@"body"] stringvalue];     nsstring *stmp=[[td elementforname:@"stamp" xmlns:@"urn:xmpp:delay"] stringvalue];     nsstring *final=[nsstring stringwithformat:@"from: %@\nto: %@\nbody: %@\nstamp: %@",from,to,bodyq,stmp];     nslog(@"forwa %@", final); 

i can able print message body , log prints

from: (null) to: (null) body: hi stamp: (null) 

fix search attributes: elements nodes (like body, result etc.) while others attributes of previous elements.

nsstring *from=[[msg attributeforname:@"from"] stringvalue];     nsstring *to=[[msg attributeforname:@"to"] stringvalue];     nsstring *stmp=[[td attributeforname:@"stamp"] stringvalue]; 

edited (sorry, last work objectivec it's old).

xml namespace it's element , not attributes.

if didn't again, try passing nsxmlnode

nsxmlnode *fromnode = [msg attributeforname:@"from"]; nsstring *from = [fromnode stringvalue]; 

Comments

Popular posts from this blog

python - How to insert QWidgets in the middle of a Layout? -

python - serve multiple gunicorn django instances under nginx ubuntu -

module - Prestashop displayPaymentReturn hook url -