1

I am working with the xml below is xml

<message xml="Local:client" type="message" to="123456@Local" from="147852369/a02c9bb1"><GET xml="http://Local.org/protocol/message"></GET></message>

Now how to get the value of "to"?.I tried with below code. But it is showing null value

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

Please any body help me.

Bhavin Bhadani
  • 22,224
  • 10
  • 78
  • 108
Bittoo
  • 579
  • 7
  • 21

2 Answers2

1

message is an element and to is attribute of message element ...

To get to from message use

[message attributeForName:@"to"]
Bhavin Bhadani
  • 22,224
  • 10
  • 78
  • 108
  • HI if you don't mind can you please check the this link [http://stackoverflow.com/questions/37048565/how-to-parse-a-xmpp-xml-in-ios] – Bittoo May 06 '16 at 08:27
0

Try following code snippet

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)")
            }

        }

}
TechSavy
  • 797
  • 2
  • 8
  • 22