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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T05:49:10+00:00 2026-06-05T05:49:10+00:00

Imagine you have a data.xml file: <?xml version=1.0 encoding=UTF-8 ?> <root> <item>value1</item> <item>value2</item> <item>value3</item>

  • 0

Imagine you have a data.xml file:

<?xml version="1.0" encoding="UTF-8" ?>
<root>
    <item>value1</item>
    <item>value2</item>
    <item>value3</item>
</root>

I’m trying to store all the data config into a single variable in order to use it in my .js code using this:

$(document).ready(function() {
        'use strict';
        jQuery.extend({
            getValues: function(url) {
            var result = null;
            $.ajax({
                url: url,
                type: 'get',
                dataType: 'xml',
                async: false,
                success: function(data) {
                result = data;
                }
            });
               return result;
            }
        });

        results = $.getValues("data.xml");
        console.log(results);
});

If I refresh the page I get in results variable a Document object with fields like URL, baseURI, body …

If I refresh again I get in results a #document object with the data from the data.xml:

<root>
    <item>value1</item>
    <item>value2</item>
    <item>value3</item>
</root>

So the type of object returned changes each time someone goes to the url.

I have two questions about this:

  1. How can I make the returned value always #document? (which contains the data from the .xml file)

  2. How can I access to an element from #document?

I have tried using:

console.log(results.root.item);
console.log(results.find("item"));

But both give me errors.

Maybe there is a better way to do this (meaning reading xml data into a single variable).

Any suggestions?

  • 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-05T05:49:12+00:00Added an answer on June 5, 2026 at 5:49 am

    You are returning the result before the ajax request has finished.
    You have to wait for the ajax to return, then call a callback function:

    $(document).ready(function() {
            'use strict';
            jQuery.extend({
                getValues: function(url, callback) {
                var result = null;
                $.ajax({
                    url: url,
                    type: 'get',
                    dataType: 'xml',
                    async: false,
                    success: function(data) {
                        callback.call(this, data);
                    }
                });
                }
            });
    
            $.getValues("data.xml",function(data){
                 console.log(data);
            });
    
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Imagine I have XML data: <tag> value</tag> etc .... <othertag> value value2 value_n </othertag>
Imagine you have a library for working with some sort of XML file or
Imagine I have a map shape file (.shp) or osm xml, I'm able to
Imagine I have a simple data file called 'test_gnu.txt' as follow: 0.32,0.116,0.398989898989899 0.34,0.010,0.01212121212121212 0.36,0.035,0.11313131313131312
imagine an xml file with 5000 sets of data. While parsing , i NSLog
Imagine I have a recursive algebraic data type like this (Haskell syntax): data Expr
imagine a situation where you have an application that needs to import data from
I have a XML file like this: <Document> <Tests> <Test> <Name>A</Name> <Value>1</Value> </Test> <Test>
Imagine I have a data frame with 2 columns Id Value 12 13 32
Possible Duplicate: C++ invoke explicit template constructor First imagine I have a class Data

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.