2016-03-05 65 views
1

我與下面的XML工作是XML如何在ios中解析xml?

<message xml="Local:client" type="message" to="[email protected]" from="147852369/a02c9bb1"><GET xml="http://Local.org/protocol/message"></GET></message> 

現在怎麼去「到」價值呢?。我試着用下面的代碼。但它顯示爲空值

[message elementForName:@"to" xml:@"Local:client"]; 

請任何機構幫助我。

回答

1

message是一個元素,to是消息元素的屬性...

從消息使用得到to

[message attributeForName:@"to"] 
+1

三江源它的工作.. .. – Bittoo

+0

嗨,如果你不介意,請你檢查這個鏈接[http://stackoverflow.com/questions/37048565/how -to-解析-A-XMPP協議,XML-在-IOS] – Bittoo

0

嘗試下面的代碼片段

func parser(parser: NSXMLParser, 
    didStartElement elementName: String, 
    namespaceURI: String?, 
    qualifiedName: String?, 
    attributes attributeDict: [NSObject : AnyObject]){ 

     println("attributess name is \([attributeDict])") 

     if elementName=="message" { 
      let attrs = attributeDict 
      if let prop = attrs["to"] { 

       println("property 'to'=\(prop)") 
      } 

     } 

}