I managed to sendIQ and get the response from openfire server.
Now I can’t traverse the response for my purposes:
There is a “find” method to search for nodes like “list”, “other1”, but I need to traverse all the types of nodes containing in the “list”. IQ-response looks like the following:
<iq type="get" id="sid_225">
<list xmlns="urn:xmpp:archive" end="2012-04-30T22:00:00Z" start="2012-03-31T22:00:00Z">
<set xmlns="http://jabber.org/protocol/rsm">
<max>30</max>
</set>
<other1> asdf </other1>
<othern> aasdf </othern>
</list>
</iq>
I need all the node types of the “list”. I got so far:
$(iq).find("list").children().each(function () {
alert($(this).text());
}
But this gives me the text like “asdf” from the different types of nodes like “other1” and “othern”. How can I get the types of the nodes (i.e. “set”, “other1”) ? I also tried $(this).val()) but it doesn’t work either.
Please help….
Thanks!
You can get the
nodeNameof each element inside your loop:You can access these variables inside the loop like above for each index in the array/object.
Here is a demo: http://jsfiddle.net/7AKL6/2/
Documentation for
.each(): http://api.jquery.com/each/Documentation for
Node.nodeName: https://developer.mozilla.org/en/Document_Object_Model_(DOM)/Node.nodeNameAlso note that your XML example has an error in it:
should be:
to properly close itself.