用javascript遍历xmpp iq节

用javascript遍历xmpp iq节,javascript,jquery,jquery-mobile,xmpp,openfire,Javascript,Jquery,Jquery Mobile,Xmpp,Openfire,我设法发送了sendIQ并从openfire服务器获得了响应 现在,出于我的目的,我无法遍历响应: 有一个“find”方法来搜索像“list”、“other1”这样的节点,但是我需要遍历“list”中包含的所有类型的节点。IQ响应如下所示: <iq type="get" id="sid_225"> <list xmlns="urn:xmpp:archive" end="2012-04-30T22:00:00Z" start="2012-03-31T22:00:00Z"&

我设法发送了sendIQ并从openfire服务器获得了响应

现在,出于我的目的,我无法遍历响应:

有一个“find”方法来搜索像“list”、“other1”这样的节点,但是我需要遍历“list”中包含的所有类型的节点。IQ响应如下所示:

 <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> 
但这给了我类似于“asdf”的文本,来自不同类型的节点,如“other1”和“othern”。如何获取节点的类型(即“set”、“other1”)?我还尝试了
$(this.val()
),但它也不起作用

请帮忙


谢谢

您可以获取循环中每个元素的
节点名

$(iq).find("list").children().each(function () {
  alert(this.nodeName + ' = ' + $(this).text());
});
对于数组/对象中的每个索引,可以像上面那样在循环中访问这些变量

下面是一个演示:

.each()
的文档:

节点.节点名的文档

还要注意,您的XML示例中有一个错误:

<other1> asdf </other>
asdf
应该是:

<other1> asdf </other1>
asdf

正确关闭自身。

非常感谢您的回答和资产!我不熟悉js和html5,你能给我推荐一个好的MVC框架来构造js和html代码吗?目前我有一个xmpp连接,如果js文件包含$(document).ready()函数,我可以跨不同的js文件使用这个连接。或者你认为这对于一个移动应用来说足够了吗?
<other1> asdf </other1>