title: Xml to Object in Swift on SOAP webservice
body: <p>I'm using a web service, by calling a web method I want to retrieve data into multiple objects, but I get a string of an xml so I want to deserialize it.</p>
  
  <p>Now I'm using a parser to retrieve each values, but I need to use objects.</p>
  
  <p>Xml Parser:</p>
  
  <pre><code>var elementValue: String?
  var elementSuccess: String?
  var elementContactWebId: String?
  var contactWebId = ""
  var success = ""
  
  func parser(parser: NSXMLParser,didStartElement elementName: String, namespaceURI: String?, qualifiedName qName: String?, attributes attributeDict: [String : String]) {
      if elementName == "code" {
          elementSuccess = String()
      }
      if elementName == "contactWebID" {
          elementContactWebId = String()
      }
  }
  
  func parser(parser: NSXMLParser, foundCharacters string: String) {
      if elementSuccess != nil {
          elementSuccess! += string
      }
      if elementContactWebId != nil {
          elementContactWebId! += string
      }
  }
  
  func parser(parser: NSXMLParser, didEndElement elementName: String, namespaceURI: String?, qualifiedName qName: String?) {
      if elementName == "code" {
          success = elementSuccess!
      }
      if elementName == "contactWebID" {
          contactWebId = elementContactWebId!
      }
  }
  
  func parser(parser: NSXMLParser, parseErrorOccurred parseError: NSError) {
      print("parseErrorOccurred: \(parseError)")
  }
  </code></pre>
  
  <p>How I call the web service (not full, xml in strData):</p>
  
  <pre><code> let session = NSURLSession.sharedSession()
  
              let task = session.dataTaskWithRequest(theRequest, completionHandler: {data, response, error -&gt; Void in
                  print("Response Login: \(response)")
                  let strData = NSString(data: data!, encoding: NSUTF8StringEncoding)!
                  print("Body Login: \(strData)")
                  if error != nil
                  {
                      print("Error Login: " + error!.description)
                  }
                  let parser = NSXMLParser(data: data!)
                  parser.delegate = self
                  parser.parse()
                  if(self.success == "1"){
                      self.successSoap = 1
                  } else {
                      self.successSoap = 0
                  }
                  self.contactWebID = Int(self.contactWebId)!
                  completion(result: self.successSoap, resultContactWebId: Int(self.contactWebId)!)
              })
  </code></pre>
  
  <p>One of my object:</p>
  
  <pre><code>class SendLeadReponse: Reponse {
      var option: SendLeadOption
  
  
      init(code: Int, message: String, option: SendLeadOption){
          self.option = option
          super.init(code: code, message: message)
      }
  
  
  }
  </code></pre>