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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T23:22:13+00:00 2026-06-09T23:22:13+00:00

How should I put this XML object into a javascript dictionary? XMLcoming in from

  • 0

How should I put this XML object into a javascript dictionary?

XMLcoming in from get_objectives.php:

<container>
  <objective>
    <id>1</id>
    <type>thing</type>
    <name>banana</name>
    <date_added>2012-05-08 21:13:01</date_added>
    <released>2012-05-08 22:47:27</released>
  </objective>
  <objective>
    <id>2</id>
    <type>thing</type>
    <name>hammock</name>
    <date_added>2012-05-08 21:13:01</date_added>
    <released>2012-05-08 22:47:27</released>
  </objective>
</container>

The javascript that doesn’t work, that I”m trying to fix:

function updateObjectives(){
  $.post('scripts/get_objectives.php', {}, function(xml){
    $(xml).find("objective").each(function(i){
      objectives[i] = {}
      objectives[i]['id'] = $('id', xml).text()
      console.log("objectives["+i+"].id = "+objectives[i].id)
    })
  })
}

Based on the console output below, it appears that the $('id', xml).text() call that I am trying isn’t stuck inside the function handling the find(“objective”).each call:

objectives[0].id = 12
objectives[1].id = 12
  • 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-09T23:22:14+00:00Added an answer on June 9, 2026 at 11:22 pm

    objectives[i]['id'] = $('id', this).text() does the trick!

    My problem was the ambigious syntax of the $() in the tutorial; $(query, context). Instead of looking for ('this > id', xml) which is looking for ‘this”s child named ‘id’ inside the full ‘xml’ file, (I already had found ‘this’!) so $('id', this) works because it is looking for ‘id’ inside ‘this’ (where ‘this’ is tags) I hope this helps someone!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: PHP detecting request type (GET, POST, PUT or DELETE) This should be
This answer suggested i should put my data in JS instead of a textarea.
Hi I have this in my application : The question is, should I put
The following jQuery example should put some text into the div, but it doesn't.
I have to implement a one linked list but it should put object in
I have to load XML from external domain, so my code looks like this
I'm attempting to parse load a rather complicated XML schema into a Schema object
I am interested in where I should apply my XML comments. Should I put
I'm running into real difficulties validating XML with XSD . I should prefix all
I am developing Liferay portlet. The portlet should load xml file from same server

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.