Not logged in. · Lost password · Register
Forum: MatriX RSS
Avatar
Hamid Wakili #1
Member since May 2013 · 6 posts
Group memberships: Members
Show profile · Link to this post
Subject: How To Return User Search Results
Hello,

I am able to search for a user and the search result is being returned as xml :) , like this :

  1. SEND: <iq id="search1" to="search.nakibfatih" type="set" from="search.nakibfatih" xmlns="jabber:client">
  2.  <query xmlns="jabber:iq:search">
  3.     <first>Hamid</first>
  4.  </query>
  5. </iq>
  6. RECV: <iq type="result" id="search1" from="search.nakibfatih" to="admin@nakibfatih/MatriX" xmlns="jabber:client">
  7.  <query xmlns="jabber:iq:search">
  8.     <item jid="hamid@nakibfatih">
  9.       <first>Hamid</first>
  10.       <email>something@example.com</email>
  11.     </item>
  12.  </query>
  13. </iq>


Now how do i filter the Results? will this work :

  1. private void RequestRoster()
  2. {
  3.     var riq = new RosterIq(IqType.get);
  4.     xmppClient.IqFilter.SendIq(riq, RosterResponse);
  5. }
  6.  
  7. private void RosterResponse(object sender, IqEventArgs e)
  8. {
  9.     var iq = e.Iq;
  10.    
  11.     if (iq.Type == IqType.result)
  12.     {
  13.         // process result here
  14.     }
  15.     else if (iq.Type == IqType.error)
  16.     {
  17.         // process errors here
  18.     }
  19. }

Looking Forward To Your Reply
This post was edited 3 times, last on 2013-05-29, 11:41 by Alex.
Avatar
Alex #2
Member since Feb 2003 · 4322 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
The Xml you posted is the query, not the result.

here is some sample code which shows you how to read the search results:

  1. private string xml = @"<iq xmlns='jabber:client' type='result'
  2.     from='search.shakespeare.lit'   
  3.     id='search2'>
  4. <query xmlns='jabber:iq:search'>
  5.     <item jid='juliet@capulet.com'>
  6.       <first>Juliet</first>
  7.       <last>Capulet</last>
  8.       <nick>JuliC</nick>
  9.       <email>juliet@shakespeare.lit</email>
  10.     </item>
  11.     <item jid='tybalt@shakespeare.lit'>
  12.       <first>Tybalt</first>
  13.       <last>Capulet</last>
  14.       <nick>ty</nick>
  15.       <email>tybalt@shakespeare.lit</email>
  16.     </item>
  17. </query>
  18. </iq>";
  19.  
  20. public void ReadSearchResults()
  21. {
  22.     XmppXElement xmpp1 = XmppXElement.LoadXml(xml);
  23.     var iq = xmpp1 as Iq;
  24.     var searchQuery = iq.Query as Matrix.Xmpp.Search.Search;
  25.     foreach (var sItem in searchQuery.GetItems())
  26.     {
  27.         Console.WriteLine(sItem.Jid.Bare);
  28.         Console.WriteLine(sItem.First);
  29.         Console.WriteLinel(sItem.Last);
  30.         Console.WriteLine(sItem.First);
  31.         Console.WriteLine(sItem.Nick);
  32.         Console.WriteLine(sItem.Email);
  33.     }   
  34. }

hope this helps.
Avatar
Hamid Wakili #3
Member since May 2013 · 6 posts
Group memberships: Members
Show profile · Link to this post
Okay Now I Understand Your Code, But That Is If You Know The Xml Return :),

But I Want To Make It Automatic, Here Is My Search DebugXml

  1. SEND: <iq id="search1" to="search.nakibfatih" type="set" from="search.nakibfatih" xmlns="jabber:client">
  2.  <query xmlns="jabber:iq:search">
  3.     <first>Hamid</first>
  4.  </query>
  5. </iq>
  6. RECV: <iq type="result" id="search1" from="search.nakibfatih" to="admin@nakibfatih/MatriX" xmlns="jabber:client">
  7.  <query xmlns="jabber:iq:search">
  8.     <item jid="hamid@nakibfatih">
  9.       <first>Hamid</first>
  10.       <email>something@example.com</email>
  11.     </item>
  12.  </query>
  13. </iq>


Since this is An OnIq Event, What Code Show I Put In The OnIq Stub ?

Here :

  1. private void xmppClient_OnIq(object sender, IqEventArgs e)
  2. {
  3.     // Instead Of This  ->   DisplayEvent("OnIq");
  4.     // What Code Should Be Here
  5.      
  6.     // Why Is This Not Working
  7.     SearchIq sIq = new SearchIq();
  8.     if (sIq.Type == IqType.result)
  9.     {
  10.     }
  11. }


Thank You Alex :)
Avatar
Alex #4
Member since Feb 2003 · 4322 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
You can send your search query with the Iq Filter. This is described here:
http://www.ag-software.net/matrix-xmpp-sdk/matrix-develope…

The result will come in the callback you pass with the Send method of the IqFilter and is already an Iq object.

  1. private void DoSearch()
  2. {
  3.     SearchIq sIq = new SearchIq();
  4.     sIq.To = "search.nakibfatih";
  5.     sIq.Type = IqType.set;
  6.     sIq.Search.Last = "some lastname";
  7.        
  8.     xmppClient.IqFilter.SendIq(sIq, SearchResultCallback);
  9. }
  10.  
  11. private void SearchResultCallback(object sender, IqEventArgs e)
  12. {
  13.     var iq = e.Iq;
  14.  
  15.     if (iq.Type == IqType.result)
  16.     {
  17.         // process result here
  18.         var searchQuery = iq.Query as Matrix.Xmpp.Search.Search;
  19.         foreach (var sItem in searchQuery.GetItems())
  20.         {
  21.             // fill your Listview
  22.         }
  23.     }
  24.     else if (iq.Type == IqType.error)
  25.     {
  26.         // process errors here
  27.     }
  28. }
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: MatriX RSS