Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 896035
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T14:39:39+00:00 2026-05-15T14:39:39+00:00

I’m creating a javascript 2D array from an XML file which I then manipulate

  • 0

I’m creating a javascript 2D array from an XML file which I then manipulate and filter as necessary before displaying on the page.

As I loop through the XML records, I manipulate the data a little, build a normal array from it (rowRecord) and then add this array to the 2D array (dataSet). Thing is, I end up with a nice 2D array, but all the records are duplicates of the very last record I’m adding.

Using some alerts I’ve found that as I add the first record, all is well. I then add the second record and I get a dataSet with 2 records, both of which are record 2. Adding the third results in a dataSet of 3 records, each of them a copy of the third record. This carries on for all 1300 records, resulting in 1300 identical records, all of which are the last record from the XML.

Here is the code:

var rowRecord     = new Array();
var dataSet       = new Array(rowRecord);

function getAjaxTridionInfo() {
   var xmlFilename = 'filename.xml';
   // make ajax call here, create xml object
   xmlData = new Ajax.Request(xmlFilename,{
      method:'get',
      onSuccess: function(transport) {
         var dataObj = transport.responseXML;
         var vRoot   = dataObj.getElementsByTagName('Items')[0];
         for (var i=0; i<vRoot.childNodes.length; i++) {
            if (vRoot.childNodes[i].nodeType == 1) {
               var tridItem = vRoot.childNodes[i];

               rowRecord[0] = tridItem.childNodes[0].firstChild.nodeValue.substring(26);
               rowRecord[1] = tridItem.childNodes[1].firstChild.nodeValue;
               rowRecord[2] = tridItem.childNodes[2].firstChild.nodeValue;
               rowRecord[3] = rowRecord[1]+"/"+rowRecord[2];
               rowRecord[4] = false;
               rowRecord[5] = "n/a";
               rowRecord[6] = "n/a";
               rowRecord[7] = false;
               rowRecord[8] = "n/a";
               rowRecord[9] = "n/a";

               //do some other processing here to determine rowRecord[4] - [9]

               dataSet.push(rowRecord);
               rowCount += 1;
            }
         }
         //call next function here
      },

      onException: function(transport, exception) {
         throw(exception);
         alert('There has been a problem performing the Ajax call');
      }
   }
   );
}

Any help or suggestions would be appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T14:39:40+00:00Added an answer on May 15, 2026 at 2:39 pm

    You should create rowRecord in the function, not outside, so as to make a new array for every row record.

    // NO NEED TO DECLARE ROWRECORD HERE...
    var dataSet = new Array(); // <- why would we add anything initially?
    
    function getAjaxTridionInfo() {
      // ...
            if (vRoot.childNodes[i].nodeType == 1) {
               var tridItem = vRoot.childNodes[i];
    
               // IMPORTANT TO MAKE A NEW ARRAY HERE
               var rowRecord = new Array();
    
               rowRecord[0] = tridItem.childNodes[0].firstChild.nodeValue.substring(26);
               rowRecord[1] = tridItem.childNodes[1].firstChild.nodeValue;
               rowRecord[2] = tridItem.childNodes[2].firstChild.nodeValue;
               rowRecord[3] = rowRecord[1]+"/"+rowRecord[2];
               rowRecord[4] = false;
               rowRecord[5] = "n/a";
               rowRecord[6] = "n/a";
               rowRecord[7] = false;
               rowRecord[8] = "n/a";
               rowRecord[9] = "n/a";
    
               //do some other processing here to determine rowRecord[4] - [9]
    
               dataSet.push(rowRecord); // <- PUSHES THE NEW ARRAY
               rowCount += 1;
            }
        // ...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I used javascript for loading a picture on my website depending on which small
In my XML file chapters tag has more chapter tag.i need to display chapters
I am trying to render a haml file in a javascript response like so:
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I have a text area in my form which accepts all possible characters from
I'm parsing an XML file, the creators of it stuck in a bunch social
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.