title: Generating XML output with jQuery, each, async problems
body: <p>I'm trying to create an XML formatted output in a textarea but have run into a asynch problems: </p>
  
  <pre><code>$(document).ready(function() {
      var geocoder;
      geocoder = new google.maps.Geocoder();
      $('#xmloutput').val('&lt;?xml version="1.0" encoding="UTF-8"?&gt;\n&lt;parent&gt;\n');
      var addresslist = 'one\ntwo\nthree';
      var addlines = addresslist.split('\n');
      $.each(addlines, function(name, value) {
          geocoder.geocode( { 'address': value}, function(results, status) {
              if (status == google.maps.GeocoderStatus.OK) {
                  $('#xmloutput').val($('#xmloutput').val()+'&lt;node&gt;'+value+'&lt;/node&gt;\n');
              }
          });
      });
      $('#xmloutput').val($('#xmloutput').val()+'&lt;/parent&gt;');
  });
  </code></pre>
  
  <p>I want this output:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;parent&gt;
  &lt;node&gt;one&lt;/node&gt;
  &lt;node&gt;two&lt;/node&gt;
  &lt;node&gt;three&lt;/node&gt;
  &lt;/parent&gt;
  </code></pre>
  
  <p>But I get this output because the geocoding takes a while...</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;parent&gt;
  &lt;/parent&gt;&lt;node&gt;one&lt;/node&gt;
  &lt;node&gt;two&lt;/node&gt;
  &lt;node&gt;three&lt;/node&gt;
  </code></pre>
  
  <p>I've seen a lot of similar posts and the fix seemes to be chaining or callback, but I've not managed to get anything working yet. How should I approach this?</p>
  
  <p>Thanks!
  Ben</p>