title: Issue with conversion of xml to JSON
body: <p>I followed the following tutorial - <a href="http://davidwalsh.name/convert-xml-json" rel="nofollow">http://davidwalsh.name/convert-xml-json</a> and getting the error :  </p>
  
  <pre><code>Uncaught exception: TypeError: 'xml.hasChildNodes' is not a function.
  </code></pre>
  
  <p>I am not sure how to resolve this? Many have posted the same thing in the site. But no luck.  </p>
  
  <p>Please help.</p>
  
  <p>Code here :  </p>
  
  <pre><code>&lt;!DOCTYPE html&gt;  
  &lt;html lang="en"&gt;  
  &lt;head&gt;  
  &lt;title&gt;Welcome&lt;/title&gt;  
  
  &lt;script type="text/javascript"&gt;  
  function myFun()  
  {  
      alert("hi..");  
      var jsonText = JSON.stringify(xmlToJson("D:/Tech/data.xml"));  
      for(var i in jsonText)  
     {
          alert(i);
     }
  }   
  
  // Changes XML to JSON  
  function xmlToJson(xml) {  
  
     // Create the return object  
     var obj = {};  
  
      if (xml.nodeType == 1) { // element  
          // do attributes  
          if (xml.attributes.length &gt; 0) {  
          obj["@attributes"] = {};  
              for (var j = 0; j &lt; xml.attributes.length; j++) {  
                  var attribute = xml.attributes.item(j);  
                  obj["@attributes"][attribute.nodeName] = attribute.nodeValue;  
              }  
          }  
       } else if (xml.nodeType == 3) { // text  
          obj = xml.nodeValue;  
      }
  
       // do children   
      if (xml.hasChildNodes()) {  
          for(var i = 0; i &lt; xml.childNodes.length; i++) {  
              var item = xml.childNodes.item(i);  
              var nodeName = item.nodeName;  
              if (typeof(obj[nodeName]) == "undefined") {  
                  obj[nodeName] = xmlToJson(item);  
               } else {  
                   if (typeof(obj[nodeName].push) == "undefined") {  
                      var old = obj[nodeName];  
                      obj[nodeName] = [];  
                      obj[nodeName].push(old);  
                  }  
                   obj[nodeName].push(xmlToJson(item));  
              }  
          }  
      }  
      return obj;  
  };  
  
   &lt;/script&gt;  
  
  &lt;/head&gt;  
  
  &lt;body onload="myFun()"&gt;  
   Hello  
  &lt;/body&gt;  
  &lt;/html&gt;  
  </code></pre>
  
  <p>And data.xml is something like here : </p>
  
  <pre><code>&lt;applications&gt;  
  &lt;application id="backupparking"&gt;  
    &lt;toplevel /&gt;   
   &lt;contexts&gt;  
   &lt;context id="Idle" /&gt;   
   &lt;context id="ABCD" /&gt;   
   &lt;context id="EFGH" /&gt;   
   &lt;context id="LMN"&gt;  
   &lt;payload&gt;  
    &lt;member id="hi" type="string" /&gt;   
    &lt;/payload&gt;  
    &lt;/context&gt;  
    &lt;/application&gt;  
    &lt;/applications&gt;  
  </code></pre>
  
  <p>Thanks!</p>