 
         if rootElementPtr != nil {
             let rootElement = rootElementPtr.memory
-            let rootElementName = String(CString: UnsafePointer<Int8>(rootElement.name), encoding: NSUTF8StringEncoding)
-            NSLog("Root element name: \(rootElementName)")
+
+            guard let rootElementName = String(CString: UnsafePointer<Int8>(rootElement.name), encoding: NSUTF8StringEncoding) else {
+                // We should evaluate how to improve this condition check... is a nil value
+                // possible at all here?  If so... do we want to interrupt the parsing or try to
+                // recover from it?
+                //
+                // For the sake of moving forward I'm just interrupting here, but this could change
+                // if we find a unit test causing a nil value here.
+                //
+                fatalError("The root element name should not be nil.")
+            }
+
+            let tag = HTMLTag(name: rootElementName)
 
             var property = rootElement.properties
 
             while (property != nil) {
-                NSLog("Property: \(String(CString: UnsafePointer<Int8>(property.memory.name), encoding: NSUTF8StringEncoding))")
+                guard let propertyName = String(CString: UnsafePointer<Int8>(property.memory.name), encoding: NSUTF8StringEncoding) else {
+                    // We should evaluate how to improve this condition check... is a nil value
+                    // possible at all here?  If so... do we want to interrupt the parsing or try to
+                    // recover from it?
+                    //
+                    // For the sake of moving forward I'm just interrupting here, but this could change
+                    // if we find a unit test causing a nil value here.
+                    //
+                    fatalError("The root element name should not be nil.")
+                }
+
+                let attribute = HTMLTag.Attribute(name: propertyName)
+                tag.attributes.append(attribute)
+
                 property = property.memory.next
             }
+
+            result.addAttribute("HTMLTag", value: tag, range: NSRange(location: 0, length: 0))
         }
 
-        return NSAttributedString(string: "")
-/*
-        let htmlPtr = UnsafePointer<Int8>(html.bytes)
-
-        xmlResetLastError()
-
-        let options = Int32(XML_PARSE_NONET.rawValue)
-        let _ = xmlReadMemory(htmlPtr, Int32(html.length), "", nil, options)
-
-        let errorPtr = xmlGetLastError()
-
-        if errorPtr != nil {
-            let messagePtr = errorPtr.memory.message
-
-            if messagePtr != nil {
-                let message = String(CString: messagePtr, encoding: NSUTF8StringEncoding)
-
-                DDLogSwift.logDebug(message)
-            }
-        }
-
-        return NSAttributedString(string: "")
-*/
-
-        /*
-        let parserDelegate = ParserDelegate()
-        let parser = NSXMLParser(data: html)
-        parser.delegate = parserDelegate
-
-        if parser.parse() {
-            return parserDelegate.output
-        } else {
-
-        }
-
-        let attributedString = NSMutableAttributedString(string: "Hello there!")
-
-        let attribute = HTMLTag(name: "HTML", attributes: nil)
-        attributedString.addAttribute("HTMLTag", value: attribute, range: NSRange(location: 0, length: attributedString.length))
-
-        return attributedString
- */
+        return result
     }
 }

import Foundation
import libxml2

public class HTMLTag {

    /// Represents a basic attribute with no value.  This is also the base class for all other
    /// attributes.
    ///
    class Attribute {
        let name: String

        init(name: String) {
            self.name = name
        }
    }



            super.init(name: name)
        }

        override public var debugDescription: String {
            get {
                return "<\(String(self.dynamicType)): {name: \(name); value: \(value)}>"
            }
        }
    }
}

