title: Parsing XML in Swift with NSXMLParser
body: <p>I have the following XML structure which I want to parse:</p>
  
  <pre><code>&lt;plist version="1.0"&gt;
          &lt;dict&gt;
              &lt;key&gt;
                  PALABRA
              &lt;/key&gt;
              &lt;array&gt;
                  &lt;string&gt;
                      CATEGORY
                  &lt;/string&gt;
                  &lt;string&gt;
                      WORD
                  &lt;/string&gt;
              &lt;/array&gt;
          &lt;/dict&gt;
  &lt;/plist&gt; 
  </code></pre>
  
  <p>I am using NSXMLParser in this way to parse the XML:</p>
  
  <pre><code>var posts = NSMutableArray()
  var parser = NSXMLParser()
  var elements = NSMutableDictionary()
  var element = NSString()
  var CATEGORY = NSMutableString()
  var WORD = NSMutableString()
  
  func parseXML() {
          posts = []
          parser = NSXMLParser(contentsOfURL:(NSURL(string:"http://www.serverbpw.com/cm/2016-1/hangman.php"))!)!
          parser.delegate = self
          parser.parse()         
  }
  
  func parser(parser: NSXMLParser, didStartElement elementName: String, namespaceURI: String?, qualifiedName qName: String?, attributes attributeDict: [String : String]) {
  
      element = elementName
      if (elementName as NSString).isEqualToString("array") {
          elements = NSMutableDictionary()
          elements = [:]
          categoria = NSMutableString()
          categoria = ""
      }
  
      if (elementName as NSString).isEqualToString("string") {
          palabra = NSMutableString()
          palabra = ""
      }
  }
  
  func parser(parser: NSXMLParser, foundCharacters string: String) {
  
      if element.isEqualToString("string") {
          categoria.appendString(string)
      }
  
      if element.isEqualToString("string") {
          palabra.appendString(string)
      }
  }
  
  func parser(parser: NSXMLParser, didEndElement elementName: String, namespaceURI: String?, qualifiedName qName: String?) {
      if (elementName as NSString).isEqualToString("array") {
          if !categoria.isEqual(nil) {
              elements.setObject(categoria, forKey: "CATEGORIA")
          }
          if !palabra.isEqual(nil) {
              elements.setObject(palabra, forKey: "PALABRA")
          }            
          posts.addObject(elements)
      }
  }
  </code></pre>
  
  <p>The value I get from the server for CATEGORY is the content of CATEGORY, but also the content of WORD, and the value for WORD is only WORD content.
  I know this is not the right way to parse the XML. The problem is that I don´t know how to get the CATEGORY and WORD elements, since both of them have the same ID ("String"). What would be the right way to get this information?</p>
  
  <p>The server address is: <a href="http://www.serverbpw.com/cm/2016-1/hangman.php" rel="nofollow">http://www.serverbpw.com/cm/2016-1/hangman.php</a></p>
  
  <p>Thanks in advance!</p>