2011-05-10 156 views
0

嘗試解析字符串中的XML時出現問題。我使用chrome,並且字符串由websocket寫入。 這是字符串中的XML:使用jQuery從字符串解析XML

<?xml version="1.0" encoding="iso-8859-1"?> 
    <event name="newchannel"> 
     <privilege>call,all</privilege> 
     <channel>SIP/NTECH-00000008</channel> 
     <channelstate>0</channelstate> 
     <channelstatedesc>Down</channelstatedesc> 
     <calleridnum>0725922523</calleridnum> 
     <calleridname /> <accountcode /> 
     <uniqueid>1305017047.8</uniqueid> 
     <actionid>1305017047_0_ALL_ALL</actionid> 
    </event> 

,我試圖得到的數據是<calleridnum>0725922523</calleridnum>。 使用此編號,將新行添加到DOM構建表(1行/新事件)中。

這是打印出一個新行jQuery的,但空:

var nrtel = $(afisare).find("calleridnum").text();

我試過其他的例子,但他們沒有打印出任何東西。

任何幫助將是偉大的。

感謝, 塞巴斯蒂安

編輯 我在Chrome控制檯

3642Uncaught Syntax error, unrecognized expression: (Presentation Allowed, Not Screened)&lt;/cid-callingpres&gt; 
&lt;actionid&gt;1305023821_0_ALL_ALL&lt;/actionid&gt; 
&lt;/event&gt; 
Sizzle.errorjquery-1.5.2.js:3642 
Sizzle.filterjquery-1.5.2.js:3628 
Sizzlejquery-1.5.2.js:3418 
Sizzlejquery-1.5.2.js:4507 
Sizzlejquery-1.5.2.js:3482 
Sizzlejquery-1.5.2.js:4507 
jQuery.fn.extend.findjquery-1.5.2.js:4747 
jQuery.jQuery.fn.jQuery.initjquery-1.5.2.js:173 
jQuery.jQueryjquery-1.5.2.js:25 

回答

0

得到這些錯誤就嘗試過了,它只是工作。

如果您使用過螢火蟲測試您的代碼,請檢查nrtel var,您可能會發現它包含您想要的內容。該行末尾的分號使螢火蟲返回未定義狀態。