Not logged in. · Lost password · Register
Forum: agsXMPP RSS
Avatar
Huntsman #1
Member since Apr 2016 · 42 posts
Group memberships: Members
Show profile · Link to this post
Subject: How to read value in iq
Hello Alex sir,
can you please help me to read value in IQ.

Return xml is

  1. <iq from="romeo@nimbuzz.com" to="romeo@nimbuzz.com/Resource" id="xmpp" type="result">
  2. <profile xmlns="http://jabber.org/protocol/profile">
  3. <x xmlns="jabber:x:data" type="result">
  4. <field var="FORM_TYPE" type="hidden">
  5. <value>http://jabber.org/protocol/profile</value>
  6. </field>
  7. <field var="highlightexpiresat">
  8. <value />
  9. </field>
  10. <field var="highlightcolor">
  11. <value />
  12. </field>
  13. <field var="badgeexpiresat">
  14. <value />
  15. </field>
  16. <field var="badge">
  17. <value />
  18. </field>
  19. <field var="status">
  20. <value />
  21. </field>
  22. <field var="nickname">
  23. <value>RoMeO</value>
  24. </field>
  25. <field var="street">
  26. <value />
  27. </field>
  28. <field var="locality">
  29. <value />
  30. </field>
  31. <field var="region">
  32. <value />
  33. </field>
  34. <field var="country">
  35. <value />
  36. </field>
  37. <field var="gender">
  38. <value>Male</value>
  39. </field>
  40. <field var="birth_year">
  41. <value />
  42. </field>
  43. <field var="birth_month">
  44. <value />
  45. </field>
  46. <field var="birth_dayofmonth">
  47. <value />
  48. </field>
  49. <field var="username">
  50. <value>romeo</value>
  51. </field>
  52. </x>
  53. </profile>
  54. </iq>

i want to read nickname, gender and username field's value.
Avatar
Alex #2
Member since Feb 2003 · 4327 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
you asked the same question here:
http://forum.ag-software.net/thread/1900-How-to-read-jid-v…

just use the code I provided in this thread. Using Linq its very easy to read the values.

Alex
Avatar
Huntsman #3
Member since Apr 2016 · 42 posts
Group memberships: Members
Show profile · Link to this post
i did the same sir. but didn't read value from that code. thats why i make a thread here and ask to you. :(
Avatar
Alex #4
Member since Feb 2003 · 4327 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
your Xml above has no <query/> element. So instead of iq.Query try iq.FirstElement.

Alex
Avatar
Huntsman #5
Member since Apr 2016 · 42 posts
Group memberships: Members
Show profile · Link to this post
i did that also. <query to <profile but still same problem. no value recieving.
Avatar
Alex #6
Member since Feb 2003 · 4327 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
using this code I am able to read your data:

  1. var doc = new Document();
  2. doc.LoadXml(xml);
  3.  
  4. var el = doc.RootElement;
  5.  
  6. var iq = el as IQ;
  7. var val = iq
  8.     .FirstChild
  9.     .SelectSingleElement<Data>()
  10.     .SelectElements<Field>()
  11.     .First(f => f.Var == "nickname").GetValue();
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 RSS