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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T01:15:02+00:00 2026-06-02T01:15:02+00:00

What I was doing is read an XML file and get the data via

  • 0

What I was doing is read an XML file and get the data via jQuery into my HTML file.

As I have found in many tutorials I am using jQuery’s .get() method. It serves me well except for one problem!

This is the XML file:

<?xml version="1.0" encoding="utf-8" ?>
<books>
  <book title="CSS Mastery" imageurl="images/css.jpg">
    <description>
      info goes here.
    </description>
  </book>

  <book title="Professional ASP.NET" imageurl="images/asp.jpg">
    <description>
      info goes here.
    </description>
  </book>

  <book title="Learning jQuery" imageurl="images/lj.jpg">
    <description>
      info goes here.
    </description>
  </book>
</books>

Here is my HTML file with jQuery codes:

<!doctype html>
<html>
  <head>
    <script type="text/javascript" src="jquery.js"></script>
    <script type="text/javascript" >
      $("document").ready(function() {
        $.get("one.xml", function(d) {
          var title = [];
          var description = [];

          $(d).find("book").each(function() {
            title.push($(this).attr("title"));
            description.push($(this).find("description").text());
          });

          console.log(title);
        });
      });
    </script>
  </head>
  <body>
    // BODY contents...
  </body>
</html>

What I want to do is I want the titles and descriptions to be returned so that i can use these arrays inside other functions. According to the jQuery code my title array is being printed in the console now but when I try to print the title array outside of the .get() method it says "title is undefined".

I have tried returning the arrays at the end of the function but no luck. I’m not sure if I have made my questions clear or not so I paste the code thats giving me the error below:

<!doctype html>
<html>
  <head>
    <script type="text/javascript" src="jquery.js"></script>
    <script type="text/javascript">
      $("document").ready(function() {
        $.get("one.xml", function(d){
          var title = [];
          var description = [];

          $(d).find("book").each(function() {
            title.push($(this).attr("title"));
            description.push($(this).find("description").text());
          });
        });

        console.log(title);
      });
    </script>
  </head>
  <body>
    // BODY contents...
  </body>
</html> 

In this block of code it is saying "title isn't defined and notice I am consoling the title array outside of the .get() method.

  • 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-02T01:15:03+00:00Added an answer on June 2, 2026 at 1:15 am

    Its because of variable scope, take a look here. If you want to use title & description in any other function of javascript then you can directly call that javascript function immediate after saving title & description(inside callback function of $.get) like follows.

    $("document").ready(function(){
    $.get("one.xml", function(d){
        var title       = [];
        var description = [];
        $(d).find("book").each(function(){
            title.push($(this).attr("title"));
            description.push($(this).find("description").text());
        });
        call_to_your_function_with_title_and_desc(title, description)
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this problem in my application: Step 1 - create an file (xml)
I am taking an XML file and reading it into various strings, before writing
I am trying to parse xml file and get no errors but when trying
I've uploaded a ZIP file containing both the XML file I'm trying to read
I am trying to read a XML document with C#, I am doing it
I need to write model data ( CharField s only) to an XML file
I have a XML file like this: <Document> <Tests> <Test> <Name>A</Name> <Value>1</Value> </Test> <Test>
I'd like to read an XML file from on my local server from my
I have to read xml files that are accessibles through http with authentication. That's
Im currently trying to read an XML file and populate an observable collection, 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.