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 8217683
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T12:32:32+00:00 2026-06-07T12:32:32+00:00

I tried to populate a two dimensoinal array through parsing xml, but my function

  • 0

I tried to populate a two dimensoinal array through parsing xml, but my function doesn’t store the first items for some unknown reason. (So it stores [0][1] and [1][1] properly, but it does not store [0][0] and [0][1]);

The idea behind the array structure is:

first word-  >  first choice  ->[0][0]; 
first word  ->  second choice ->[0][1]; 
second word ->  first choice  ->[1][0];
... you can guess

It alerts everytime (just to check that counters are correct.)

The XML:

<?xml version="1.0" encoding="utf-8" ?>
 <Page>
  <Word id = "0">
    <Choice id = "0">
     <text>First word - 1. choice</text>
    </Choice>
    <Choice id = "1">
     <text>First word - 2. choice</text>
    </Choice>
  </Word>
 <Word id= "1">
  <Choices>
    <Choice id = "0">
      <text>Second word - First choice</text>
    </Choice>
    <Choice id= "1">
     <text>Second word - Second Choice</text>
    </Choice>
  </Choices>
 </Word>
</Page>

The function:

$(document).ready(function()
{
 $.ajax({
 type: "GET",
 url: "xml.xml",
 dataType: "xml",
 success: parseXml2
  });
});

function parseXml2(xml) {

var myArray = [];
var a = 0;

$(xml).find("Word").each(function() {
    var i = $(this).attr("id");
    a = 0;

    $(this).find("Choice").each(function() {
        alert('I:' + i + 'A:' + a);
        alert('Id:' + $(this).attr("id") + $(this).text());
        myArray[i] = [];
        var text = $(this).text();
        myArray[i][a] = text;
        a++;
    });
});

alert(myArray[0][0]);

}

parseXml2(xml);​

The code can also be found here.

  • 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-06-07T12:32:33+00:00Added an answer on June 7, 2026 at 12:32 pm

    It’s because you set myArray[i] = []; on each iteration. Set it in this loop $(xml).find("Word").each(function() { not the second one. vágod :D?

    this should work:

    $(xml).find("Word").each(function() {
        var i = $(this).attr("id");
        a = 0;
        myArray[i] = [];
        $(this).find("Choice").each(function() {
            alert('I:' + i + 'A:' + a);
            alert('Id:' + $(this).attr("id") + $(this).text());
    
            var text = $(this).text();
            myArray[i][a] = text;
            a++;
        });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have tried for the last two days to get some code to work,
tried uncommenting pam_limits.so from the pam.d directory but no luck. Basic PAM seems to
Tried searching the site, but cannot find an answer to my problem: Lets say
Tried this: $('.link').click(function(e) { $.getScript('http://www.google.com/uds/api?file=uds.js&amp;v=1.0', function() { $('body').append('<p>GOOGLE API (UDS) is loaded</p>'); }); return
Tried a bunch of things but I can't get it to work consistently amid
tried to find the answer by googling and in MSDN but with no luck.
I'm currently working with two tables that I'm accessing through NHibernate entity framework: -
Want to populate two NSMutableArray s to 2 Custom Sections of tableView ; I
in Mongoose i have two Schemas, which are linked using Mongoose populate : var
I ultimately have two areas with a few questions each about Entity Framework, but

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.