Not logged in. · Lost password · Register
Forum: agsXMPP SDK Support RSS
Avatar
kstevens #1
Member since Sep 2008 · 3 posts
Group memberships: Members
Show profile · Link to this post
Subject: PubSub tags
Hi,

I am currently working on a little pub sub application to simply send out various data to the users subscribed to the relavant node. This all works fine, I can publish a message and the subscribed users recieve the message.

The problem comes when trying to "decode" the xml message received. For example... the message recieved by subscribed users is shown below.

<message xmlns="jabber:client" from="pubsub.welld407296" to="admin@welld407296">
   <event xmlns="http://jabber.org/protocol/pubsub#event">
      <items node="/home/welld407296/admin">
          <item id="4C656861B2B60">
             <tag1>Hello value 1</tag1>
             <tag2>Hello value 2</tag2>
             <tag3>Hello value 3</tag3>
          </item>
       </items>
    </event>
</message>

I wish to be able to extract the tags and contents of the tags. I am able to successfully obtain the contents of the tags with the code below.

void connection_OnMessage(object sender, agsXMPP.protocol.client.Message msg)
{
    agsXMPP.protocol.extensions.pubsub.@event.Event pubSubEvent =
    msg.SelectSingleElement(typeof(agsXMPP.protocol.extensions.pubsub.@event.Event)) as
    agsXMPP.protocol.extensions.pubsub.@event.Event;
           
    if (pubSubEvent != null)
    {
         agsXMPP.protocol.extensions.pubsub.@event.Items eventItems = pubSubEvent.Items;

         int i = eventItems.FirstChild.ChildNodes.Count;
         int j = 0;
         for(j = (i-1); j>=0; j--)
         {
             try
             {                
                 addIncomingRTF(eventItems.FirstChild.ChildNodes.Item(j).Value + "\n", red, bold);
             }
              
             catch { }
         }
    }
}

The code sends the contents of each tag to the addIncomingRTF method which then adds the text to an RTF box. I have yet to find out a way to decode the tag names. I could create a text parser but I figured that there is probably a method already to created to gain the tag names.

By using "eventItems.FirstChild.TagName" I am able to get the name of the parent tag (in this case, item), but not the lower level ones.

Any help would be appreciated,

Thanks,


Kai Stevens.
Avatar
Alex #2
Member since Feb 2003 · 4245 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
eventItems.FirstChild.ChildNodes.Item(j).TagName gives you the tagname.
agsXMPP.Xml.Dom gives you the classes to build and read the Xml pretty easy.

You should also study the document "creating your custom packets" to write your own classes for your pubsub payloads.

Alex
Alexander Gnauck
AG-Software
Avatar
kstevens #3
Member since Sep 2008 · 3 posts
Group memberships: Members
Show profile · Link to this post
Thanks for the reply.

It seems appending ".TagName" does not work. It gives the following error.

Error    1    'agsXMPP.Xml.Dom.Node' does not contain a definition for 'TagName' and no extension method 'TagName' accepting a first argument of type 'agsXMPP.Xml.Dom.Node' could be found (are you missing a using directive or an assembly reference?)    C:\vs\pubsub\pubsub\Form1.cs    458    76    pubsub

I will have a read of that "creating you custom packets" document today.

Thanks,


Kai Stevens.
Avatar
Jabberer #4
Member since Feb 2006 · 249 posts
Group memberships: Members
Show profile · Link to this post
Node is the base class which has no TagName. Only Elements, so you have to cast your object to Type Element.
Software Developer
AG-Software
Avatar
kstevens #5
Member since Sep 2008 · 3 posts
Group memberships: Members
Show profile · Link to this post
That did the trick.

Thanks very much.
Close Smaller – Larger + Reply to this post:
Verification code: VeriCode Please enter the word from the image into the text field below. (Type the letters only, lower case is okay.)
Smileys: :-) ;-) :-D :-p :blush: :cool: :rolleyes: :huh: :-/ <_< :-( :'( :#: :scared: 8-( :nuts: :-O
Special characters:
Forum: agsXMPP SDK Support RSS