[JDEV] Sending message in xml tags

Heiner Wolf wolf at bluehands.de
Wed Apr 23 08:51:29 CDT 2003


Of course, I forgot, 
Since it is always good practice to promote the own library :-)

For a project I wrote a class to create XML. It goes like:

  XMLNode message("message");
  XMLNode* x= message.AddChild("x");
  x->AddAttribute("xmlns", "http://abc/jabber");
  x->AddChild("forward ");
etc.
  char *data = message.OuterXml();

The class is included in the publicly available source of the LLuna client: http://www.lluna.de

--
Dr. Klaus H. Wolf
bluehands GmbH & Co.mmunication KG
http://www.bluehands.de/people/hw
+49 (0721) 16108 75
 

> -----Original Message-----
> From: Matt Tucker [mailto:matt at jivesoftware.com]
> Sent: Wednesday, April 23, 2003 2:59 PM
> To: jdev at jabber.org
> Subject: Re: [JDEV] Sending message in xml tags
> 
> 
> Satish,
> 
> You can always add and remove XML elements on the fly and 
> then use XML 
> parsing routines to figure out incoming packets. However, it 
> sounds like 
> you're just looking for a very simple way to to programatically pass 
> info back and forth between two XMPP nodes? If so, I'd recommend 
> checking out our Open Source client library Smack -- 
> http://www.jivesoftware.com/xmpp/smack
> 
> The feature that may help you most is the ability to attach 
> an arbitrary 
> map of data (including Java objects) to each packet. As an example:
> 
> Setting Properties:
> 
> Message message = chat.createMessage();
> // Add a Color object as a property.
> message.setProperty("favoriteColor", new Color(0, 0, 255));
> // Add an int as a property.
> message.setProperty("favoriteNumber", 4);
> chat.sendMessage(message);
> 
> Getting those same properties would use the following code:
> 
> Message message = chat.nextMessage();
> // Get a Color object property.
> Color favoriteColor = (Color)message.getProperty("favoriteColor");
> // Get an int property. Note that properties are always returned as
> // Objects, so we must cast the value to an Integer, then convert
> // it to an int.
> int favoriteNumber = 
> ((Integer)message.getProperty("favoriteNumber")).intValue();
> 
> 
> This is a different solution than what you were asking for, 
> but it could 
> be much simpler if I understand the problem you're trying to solve.
> 
> Regards,
> Matt
> 
> Satish Plakote wrote:
> > hi 
> > i am using muse api from http://www.echomine.org/projects/muse/
> > Trying to develope a java client.
> >  
> > Let me put it through an example
> > I want to send a XML info of this type to a user ' xyz '.
> >  
> >  <message to="icm at jabber">
> >  <x xtype="forward" xmlns="http://abc/jabber">
> >    <forward call="callid" to="xyz at jabber" />
> >    </x>
> >  </message>
> >  
> >  I will be adding /deleting nodes on the fly.
> >  I have not been able to come across classes/Api's that allow 
> >  me to do it.
> >  I can send plain mesages to any user,but not in XML format.
> >  I hope i have been clear abt my problem.
> >  I would appreciate links that give me some good code sample 
> >  rather than
> >  theory.
> >  
> >  
> >  Rgds
> > Satish
> >  
> > 
> > 
> > _______________________________________________
> > jdev mailing list
> > jdev at jabber.org
> > http://mailman.jabber.org/listinfo/jdev
> 
> _______________________________________________
> jdev mailing list
> jdev at jabber.org
> http://mailman.jabber.org/listinfo/jdev
> 



More information about the JDev mailing list