0
votes

I managed to get the response from the prosody XMPP server. As a result, I got the iq stanza for my roster query.

<iq xmlns="jabber:client" id="1:sendIQ" type="result" to="server@localhost/c38649b9-b47f-46b9-bcbc-7f0f683408f1">
  <query xmlns="jabber:iq:roster" ver="41">
    <item jid="sam@internal" subscription="none"/>
    <item jid="[email protected]" subscription="none"/>
    <item jid="blade@internal" subscription="none"/>
  </query>
</iq>

I want to get the value of JID from the item tag. For instance, sam@internal from the item tag.

so far I successfully reached to item tag by using below javascript code. But I want to traverse to "jid".

$(iq).find("query").children().each(function () { alert(this.nodeName + ' = ' + $(this).text()); });

here is the running code on jsfiddle: http://jsfiddle.net/ritter17/ec272rux/

Any help would be appreciated!! Thanks in advance.

1
Are you sure that jQuery code works? I can see two things wrong with it. $(iq) should be $('iq'), and there's no "list" element to find in that stanza.Andy
@Andy I am sure that it is working since I changed the typo error (query instead of list). getting these values. But I want to get the value of JID from item node. item = item = item =Ankit Ramani

1 Answers

0
votes

Here is the answer after unsuccessful attempts.

x=iq.getElementsByTagName('item');

        for (i=0;i<x.length;i++)
        {
          $("#msgs").prepend("<p><strong>" + "server" + "</strong>: " + x[i].getAttribute('jid') + "</p>");
          console.log(x[i].getAttribute('jid'));
        }