2014-11-24 97 views
-1

我有一個來自nimbuzz聊天應用程序的xml代碼,它使用input關鍵字在nimbuzz服務器中搜索chatroom。從python的xml代碼獲取結果

<iq type="set" id="Nimbuzz_SearchRooms" to="conference.nimbuzz.com"><query xmlns="jabber:iqearch"><set xmlns="http://jabber.org/protocol/rsm"><index>0</index><max>10</max></set><x type="get" xmlns="jabberata"><field var="name"><value>**INPUT KEYWORD FOR ROOM NAME**</value></field><field var="include_password_protected"><value>true</value></field></x></query></iq> 

的代碼工作,我得到下面的結果作爲XML代碼:

看到圖像:

The result code image

我開始使用此代碼,但我可以完成它,因爲我不明白它是如何工作的:

def handler_search_room(type, source, parameters): 
    Key_word = raw_input("Please write the Key word: ") 
    if parameters.split(): 
     iq = xmpp.Iq('set') 
     iq.setID('Nimbuzz_SearchRooms') 
     iq.setTo('conference.nimbuzz.com) 

我需要將第一個代碼發送到nimbuzz服務器,然後我需要獲得每個Chatroom的信息結果。 結果代碼應該得到每個聊天室這樣的信息:

  • 主題。

  • NUM_USERS

  • num_max_users

  • is_passowrd_protected

  • is_member_only

  • 語言

  • 位置型

  • 位置

我如何能做到這一點與Python?如果有人能幫我做我的代碼,我會很高興。

下載的XML代碼,如果你想:

http://qfs.mobi/f1833350

回答

0
def handler_akif_room(type, source, parameters): 
     room = parameters 
     if parameters.split(): 
     iq = xmpp.Iq('set') 
     iq.setID('Nimbuzz_SearchRooms') 
       iq.setTo('conference.nimbuzz.com') 
       query = xmpp.Node('query') 
       query.setNamespace('jabber:iq:search') 
       iq.addChild(node=query) 

       sett = xmpp.Node('set') 
       sett.setNamespace('http://jabber.org/protocol/rsm') 
       query.addChild(node=sett) 

       sifir = "0" 
       ind = xmpp.Node('index') 
       ind.setData(sifir) 
       sett.addChild(node=ind) 

       on = "10" 
       maxx = xmpp.Node('max') 
       maxx.setData(on) 
       sett.addChild(node=maxx) 

       qqx = xmpp.Node('x') 
       qqx.setNamespace('jabber:x:data" type="get') 
       query.addChild(node=qqx) 

       field = xmpp.Node('field') 
       field.setAttr('var','name') 
       field.setData(' ') 
       qqx.addChild(node=field) 

       valueone = xmpp.Node('value') 
       valueone.setData(room) 
       field.addChild(node=valueone) 



       fieldtwo = xmpp.Node('field') 
       fieldtwo.setAttr('var','include_password_protected') 
       fieldtwo.setData(' ') 
       qqx.addChild(node=fieldtwo) 

       valuetwo = xmpp.Node('value') 
       valuetwo.setData('true') 
       fieldtwo.addChild(node=valuetwo) 


     JCON.SendAndCallForResponse(iq, handler_akif_room_answ, {'type': type, 'source': source}) 
     msg(source[1], u''+str(iq)+' .') ## <= OUT SHOW :)) GOOD WORK! CONTACT ME [email protected] :)