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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T17:32:55+00:00 2026-05-29T17:32:55+00:00

I am currently working on a page that will read in XML files that

  • 0

I am currently working on a page that will read in XML files that are in a directory (dynamically) and then send them back to the client via JSON. However I’m not sure how to reference the dynamic elements of the JSON array that is returned. EG.

$.getJSON('getfilenames.php', function(data) {
    for(var i in data)
    {
        var temp3 = data[i].name;(<-- if I dont know what .name was)
        var temp2 = temp3.replace(".xml","");
        temp = temp +'<option value="'+temp3+'">' +temp2 +'</option>';
    }
    temp = temp +'</select>';
    $("#div2").html(temp);
}

If I didn’t already know what the .name element within data was, how could I :
A: retrieve a list of them for referencing, or B: access the data to do it myself.
I am also curious as to how I go about getting elements from within elements. EG:

{"contact":{"@attributes":{"id":"1"},"name":"John Doe","phone":"123-456-7890","address":"\n 123 JFKStreet\n "}}

How would I get the name attribute out.

  • 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-29T17:32:56+00:00Added an answer on May 29, 2026 at 5:32 pm

    You just need to iterate over the properties of the returned object..

    for (var prop in data[i]){
       // prop hold the name of the property (name) in your example
       // do something with data[i][prop]
    }
    

    You can go as deep in an object with multiple . notation..

    from your last example (assuming the variable holding this object is data)

    data.contact.name // "John Doe"
    data.contact['@attributes'].id // 1 - we used the [] syntax because of @
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently working on a page that loads several images sequentially using setTimeout and
I am currently working on a page that has a date picker for one
I'm currently working on a project with a one page design that'll slide up
Currently I am working on a web page that has six ReportViewer controls that
The ASP.net page I am currently working on has a drop down list that
I have written a page that will scan a site and then extract certain
I am working on a site that has a page that will have a
I currently working on an issue tracker for my company to help them keep
Am currently working on an application that requires users to submit posts and comments
I'm currently working on a wordpress 2.9.2 plugin (my first) that creates additional custom

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.