title: Problem with eBay API Parsing XML to Google Script
body: <p>I am trying to call the eBay API GetMyeBaySelling I can get Act, Timestamp, Version and Build to return and write it to a Google Sheet but no matter what I try I can not get the 'Item' list to return. The Response is below and I need help getting any of the other fields. Lets say I want to loop through and return 'BuyItNowPrice' for all the returned listings. I have tried the the code below but I am getting nowhere fast.</p>
  <p>I am more used to Excel VBA but trying to transition to Google Sheets Script.</p>
  <p>API Response:</p>
  <pre><code>[20-09-15 19:52:46:012 BST] Logging output too large. Truncating output. &lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
  &lt;GetMyeBaySellingResponse xmlns=&quot;urn:ebay:apis:eBLBaseComponents&quot;&gt;&lt;Timestamp&gt;2020-09-15T18:52:45.627Z&lt;/Timestamp&gt;&lt;Ack&gt;Success&lt;/Ack&gt;&lt;Version&gt;1163&lt;/Version&gt;&lt;Build&gt;E1163_CORE_APISELLING_19187371_R1&lt;/Build&gt;&lt;ActiveList&gt;&lt;ItemArray&gt;&lt;Item&gt;&lt;BuyItNowPrice currencyID=&quot;GBP&quot;&gt;3.99&lt;/BuyItNowPrice&gt;&lt;ItemID&gt;##########&lt;/ItemID&gt;&lt;ListingDetails&gt;&lt;StartTime&gt;2011-09-16T10:51:54.000Z&lt;/StartTime&gt;&lt;ViewItemURL&gt;https://www.ebay.co.uk/itm/???????????????????????????-/############&lt;/ViewItemURL&gt;&lt;ViewItemURLForNaturalSearch&gt;http://cgi.ebay.co.uk/????????item=############&amp;amp;category=51169&amp;amp;cmd=ViewItem&lt;/ViewItemURLForNaturalSearch&gt;&lt;/ListingDetails&gt;&lt;ListingDuration&gt;GTC&lt;/ListingDuration&gt;&lt;ListingType&gt;StoresFixedPrice&lt;/ListingType&gt;&lt;Quantity&gt;70&lt;/Quantity&gt;&lt;SellingStatus&gt;&lt;CurrentPrice currencyID=&quot;GBP&quot;&gt;3.99&lt;/CurrentPrice&gt;&lt;/SellingStatus&gt;&lt;ShippingDetails&gt;&lt;ShippingServiceOptions&gt;&lt;ShippingServiceCost currencyID=&quot;GBP&quot;&gt;0.0&lt;/ShippingServiceCost&gt;&lt;/ShippingServiceOptions&gt;&lt;ShippingType&gt;Flat&lt;/ShippingType&gt;&lt;/ShippingDetails&gt;&lt;TimeLeft&gt;PT15H59M9S&lt;/TimeLeft&gt;&lt;Title&gt;????????????????????????????&lt;/Title&gt;&lt;WatchCount&gt;3&lt;/WatchCount&gt;&lt;QuestionCount&gt;3&lt;/QuestionCount&gt;&lt;QuantityAvailable&gt;0&lt;/QuantityAvailable&gt;&lt;SKU&gt;???????&lt;/SKU&gt;&lt;PictureDetails&gt;&lt;GalleryURL&gt;http://thumbs.ebaystatic.com/pict/???????????_5.jpg&lt;/GalleryURL&gt;&lt;/PictureDetails&gt;&lt;NewLeadCount&gt;3&lt;/NewLeadCount&gt;&lt;ClassifiedAdPayPerLeadFee currencyID=&quot;GBP&quot;&gt;0.0&lt;/ClassifiedAdPayPerLeadFee&gt;&lt;SellerProfiles&gt;&lt;SellerShippingProfile&gt;&lt;ShippingProfileID&gt;??????????&lt;/ShippingProfileID&gt;&lt;ShippingProfileName&gt;Flat:Royal Mail 2nd(Free),Royal Mail Tra,Same#79&lt;/ShippingProfileName&gt;&lt;/SellerShippingProfile&gt;&lt;SellerReturnProfile&gt;&lt;ReturnProfileID&gt;????????????&lt;/ReturnProfileID&gt;&lt;ReturnProfileName&gt;Returns Accepted,Buyer,30 days#2&lt;/ReturnProfileName&gt;&lt;/SellerReturnProfile&gt;&lt;SellerPaymentProfile&gt;&lt;PaymentProfileID&gt;124284320022&lt;/PaymentProfileID&gt;&lt;PaymentProfileName&gt;PayPal#0&lt;/PaymentProfileName&gt;&lt;/SellerPaymentProfile&gt;&lt;/SellerProfiles&gt;&lt;HideFromSearch&gt;true&lt;/HideFromSearch&gt;&lt;ReasonHideFromSearch&gt;OutOfStock&lt;/ReasonHideFromSearch&gt;&lt;OutOfStockControl&gt;true&lt;/OutOfStockControl&gt;&lt;/Item&gt;&lt;Item&gt;
  </code></pre>
  <p>My Code:</p>
  <pre><code>    var response = UrlFetchApp.fetch(site, options);
  
    
     var document = XmlService.parse(response);
    Logger.log(response);
    var root = document.getRootElement();
    var NS = XmlService.getNamespace(&quot;urn:ebay:apis:eBLBaseComponents&quot;);
     
    var ack = root.getChildText('Ack', NS);
    var time = root.getChildText('Timestamp', NS);
    var version = root.getChildText('Version', NS);
    var build = root.getChildText('Build', NS);
    var shortmessage = root.getChildText('ShortMessage', NS);
     //Logger.log(shortmessage);  
    var longmessage = root.getChildText('LongMessage', NS);
     //Logger.log(longmessage);
    
    var itms = root.getChild('ActiveList', NS).getChild('ItemArray', NS).getChild('BuyItNowPrice', NS);
          Logger.log(itms + '1st Log');
    for (var i = 0; i &lt; itms.length; i++) {
      var item = itms[i].getChild('Item', NS).getText();
        Logger.log(item + '2nd Log');
    }
  
      //sheet.getRange('A2').setValue(xml);
     var LstSheet = sheet.getLastRow()+1
     sheet.getRange(LstSheet, 1).setValue([ack]);
     sheet.getRange(LstSheet, 2).setValue([time]);
     sheet.getRange(LstSheet, 3).setValue([version]);
     sheet.getRange(LstSheet, 4).setValue([build]);
     sheet.getRange(LstSheet, 5).setValue([shortmessage]);
     sheet.getRange(LstSheet, 6).setValue([longmessage]);
  
  
  </code></pre>
  <p>Thanks in Advance</p>
  <p>UPDATE: 16-09-2020 @ 17:08hrs UK:  OK, I now have working code and it writes data to the sheet but it takes about 82 seconds to write 200 records in 4 columns. Would it be quicker to write the data to an array then add it to the sheet?  If it would be faster can you help with an example. In fact, it would be good to see how to write it to an array anyways, then to the sheet, so I can learn some more.</p>
  <p>My working code:</p>
  <pre><code>  var itms = root.getChild('ActiveList', NS).getChild('ItemArray', NS).getChildren();
    for (var i = 0; i &lt; itms.length; i++) {
      
      var item = itms[i].getChild('ItemID', NS).getText();
      var title = itms[i].getChild('Title', NS).getText()
      var url = itms[i].getChild('ListingDetails', NS).getChild('ViewItemURLForNaturalSearch', NS).getText()
      var imgurl = itms[i].getChild('PictureDetails', NS).getChild('GalleryURL', NS).getText()
      
      
      sheet.appendRow([item, title, url, imgurl]);
  </code></pre>