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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T15:12:14+00:00 2026-06-08T15:12:14+00:00

I am having a problem with getElementsByTagName. I am trying to pull information from

  • 0

I am having a problem with getElementsByTagName. I am trying to pull information from an xml file I received from the server using ajax. In IE it is works fine, but when I try to run it on Chrome or FireFox I get an “undefined”.

Javascript:

function parseMessage()
{
    doc = request.responseXML;
    sum = "";

    for (var i=0; i< doc.getElementsByTagName('coupon').length; i=i+1)
    {
        var lat2 = doc.documentElement.getElementsByTagName('latitude').item(i).text;
        var longi2 = doc.documentElement.getElementsByTagName('longitude').item(i).text;
        var latlng  = new google.maps.LatLng( lat2 , longi2 ); 
        var product =  doc.documentElement.getElementsByTagName('productname').item(i).text;
        // marker[i] = createMarker(map2, product, latlng, description);

        sum = sum + description+ " "+ product + lat2 + longi2;                          
    }

    document.write(sum);
}           

XML:

<?xml version="1.0" encoding="UTF-8"?>
-<coupons>
-<coupon id="1">
<productname>Bigmac</productname>
<companyname>Macdonalds</companyname>
<latitude>32.015954</latitude>
<longitude>34.755228</longitude>
</coupon>
-<coupon id="2">
<productname>Crocs</productname>
<companyname>Crocs</companyname>
<latitude>32.079375</latitude>
<longitude>34.769325</longitude>
</coupon>
-<coupon id="3">
<productname>Nike Shoks</productname>
<companyname>NIKE</companyname>
<latitude>32.048825</latitude>
<longitude>34.785461</longitude>
</coupon>
-<coupon id="4">
.....
  • 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-08T15:12:15+00:00Added an answer on June 8, 2026 at 3:12 pm

    The first problem is that getElementsByTagName() returns a list of elements; which can’t be operated on as a group, so you’d have to select a particular node on which to work:

    getElementsByTagName('latitude')[0]; // for the first element.
    

    The second problem is that:

    getElementsByTagName('latitude')[0].item(i);
    

    Should be used to access a property, or attribute, of a particular element, and item(i) is neither, though it may be set/used somewhere that we’re not seeing.

    If you’re trying to access one of the element’s children (and in your posted code the latitude elements don’t have any children), you could use:

    getElementsByTagName('latitude')[0].childNodes[i];
    

    And text() doesn’t return, or do, anything in plain JavaScript. If you’re using the jQuery text() method, then that only works on jQuery objects, if you’re trying to access the text content of the current nodes, then:

    getElementsByTagName('latitude')[0].textContent; // for Firefox, Chrome...
    

    Or:

    getElementsByTagName('latitude')[0].innerText; // for IE
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having a bit of an issue. I'm parsing a large xml file using
I am having problem transforming xml to xml using xsl. I found out where
I am having problem using mvc:resources in spring 3.1 configuration. Initially i was working
I'm having a problem with encoding from a wordpress feed that I just can't
I'm trying to use Javascript to pull data from Yahoo Weather (eg http://weather.yahooapis.com/forecastrss?w=9807&u=c ).
Possible Duplicate: How to read XML response from a URL in java? I'm trying
I have a problem with WPF and XML. What I am trying to do
hi I'm having problem with my database. I'm using access as my database and
I am having problem understanding Priority Inversion Snippet from the article: Consider there is
I'm having a strange problem when trying to updated a div with a couple

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.