title: Unwanted field in xml to json conversion?
body: <p>How can I remove the text value in the json string if it is empty and show up only if it has text nodetype.
  "#text":["\n\t\t","\n\t\t","\n\t\t","\n\t\t","\n\t"],</p>
  
  <p>What may be the reason for this output, </p>
  
  <p><strong>xmldoc.xml</strong></p>
  
  <pre><code>&lt;ALEXA VER="0.9" URL="davidwalsh.name/" HOME="0" AID="="&gt;
      &lt;SD TITLE="A" FLAGS="" HOST="davidwalsh.name"&gt;
          &lt;TITLE TEXT="David Walsh Blog :: PHP, MySQL, CSS, Javascript, MooTools, and Everything Else"/&gt;
          &lt;LINKSIN NUM="1102"/&gt;
          &lt;SPEED TEXT="1421" PCT="51"/&gt;
          &lt;limit TEXT="12222" PCT="87"/&gt;
      &lt;/SD&gt;
      &lt;SD&gt;
          &lt;POPULARITY URL="davidwalsh.name/" TEXT="7131"/&gt;
          &lt;REACH RANK="5952"/&gt;
          &lt;RANK DELTA="-1648"/&gt;
          &lt;limit TEXT="122yastd22" PCT="87"/&gt;
      &lt;/SD&gt;
  &lt;/ALEXA&gt;
  </code></pre>
  
  <p><strong>script code in index.html:</strong></p>
  
  <pre><code>&lt;script&gt;
  
  if (window.XMLHttpRequest)
    {// code for IE7+, Firefox, Chrome, Opera, Safari
    xmlhttp=new XMLHttpRequest();
    }
  else
    {// code for IE6, IE5
    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.open("GET","xmldoc.xml",false);
    xmlhttp.send();
    xmlDoc=xmlhttp.responseXML; 
  
  var jsonText = JSON.stringify(xmlToJson(xmlDoc));
  
  //alert(jsonText);
  
  document.write(jsonText);
  
  // 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;
  </code></pre>
  
  <p><strong>output in json:</strong></p>
  
  <pre><code> {"ALEXA":{"@attributes":{"VER":"0.9","URL":"davidwalsh.name/","HOME":"0","AID":"="},"#text":["\n\t","\n\t","\n"],"SD":[{"@attributes":{"TITLE":"A","FLAGS":"","HOST":"davidwalsh.name"},"#text":["\n\t\t","\n\t\t","\n\t\t","\n\t\t","\n\t"],"TITLE":{"@attributes":{"TEXT":"David Walsh Blog :: PHP, MySQL, CSS, Javascript, MooTools, and Everything Else"}},"LINKSIN":{"@attributes":{"NUM":"1102"}},"SPEED":{"@attributes":{"TEXT":"1421","PCT":"51"}},"limit":{"@attributes":{"TEXT":"12222","PCT":"87"}}},{"#text":["\n\t\t","\n\t\t","\n\t\t","\n\t\t","\n\t"],"POPULARITY":{"@attributes":{"URL":"davidwalsh.name/","TEXT":"7131"}},"REACH":{"@attributes":{"RANK":"5952"}},"RANK":{"@attributes":{"DELTA":"-1648"}},"limit":{"@attributes":{"TEXT":"122yastd22","PCT":"87"}}}]}} 
  </code></pre>