2016-03-05 57 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)") 
      } 

     } 

}