   # Function to convert XML to JSON 
   # Reference: http://goessner.net/download/prj/jsonxml/
   json2xml: (json, tab) ->
+    xml = ""
     # Recursive function to transveres through child JSON objects
-    toXml: (v, name, ind) ->
+    toXml = (v, name, ind) ->
       # define XML variable to be global
       $a.xml = "";
       # If JSON element is an Array

        
        # Continue on if JSON element has child elements
        if hasChild
          for key in v
            # If element key is of type text (no XML tag created)
            if key == "#text"
              $a.xml += v[key]
            else if key == "#cdata"
              $a.xml += "<![CDATA[" + v[key] + "]]>"
            # Else if element is not an XML attribute it has children
            else if key.charAt(0) != "@"
              $a.xml += toXml v[key], m, ind+"\t"
            
          # Add indentation for new element if it is on a new line 
          if $a.xml.charAt($a.xml.length-1) == "\n"

      else if typeof(v) == "object" 
        hasChild = false
        $a.xml += ind + "<" + name
        for key of v
          # If element has "@" character at beginning it is an attribute
          if key.charAt(0) == "@"
            $a.xml += " " + key.substr(1) + "=\"" + v[key].toString() + "\""
