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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T06:33:09+00:00 2026-05-29T06:33:09+00:00

I’m trying to test if the xml file have the tag <group> var xmlhttp

  • 0

I’m trying to test if the xml file have the tag “<group>“

var xmlhttp = new window.XMLHttpRequest();
xmlhttp.open("GET", "xmlfile.xml", false);
xmlhttp.send(null);
xml = xmlhttp.responseXML.documentElement; 

var thegroup = xml.getElementsByTagName('group')[0];
if (!group) {
    alert('No <group> in the XML: ' + xml);
    return;
} else {
    alert(xml + 'have a <group> tag');
}

Even if my xml file have the tag “<group>” the result is always negative, and the variable “thegroup” is undefined.

“xml” give me “[object Element]”

Where is my mistake?

PS: I’m only interested in webkit, I don’t care about IE, Opera or Firefox for now.

EDIT : HERE IS MY ACTUAL CODE

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html>
<head>
<meta http-equiv="CONTENT-TYPE" content="text/html; charset=UTF-8">
<title>xmltest</title>
<script type="text/javascript">

function init() {

var xmlhttp = new window.XMLHttpRequest();
xmlhttp.open("GET", "xmlfile.xml");
xmlhttp.send(null);
xmlhttp.onreadystatechange = callbackFunction;

function callbackFunction(){
  if (xmlhttp.readyState == 4){
     xml = xmlhttp.responseXML.documentElement; 
    var group = xml.getElementsByTagName('group')[0];
    console.debug(xml)
    if (!group) {
      alert('No <group> in the XML: ' + xml);
      return;
    } else {
      alert(xml + 'have a <group> tag');
    }
  }
}

};

</script>
</head>
<body onLoad="init();">

</body>
</html>

and my xmlfile.xml :

<?xml version="1.0" ?>

<group type="vertical">
<name>name</name>
<title>title</title>
</group>

At this point the alert is triggered saying :
No <group> in the XML: [object Element]

So maybe my problem is just on the way I try to find the <group> tag ?

  • 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-29T06:33:10+00:00Added an answer on May 29, 2026 at 6:33 am

    XMLHttpRequest is asynchronous, it doesn’t work that way. When you use xmlhttp.send(null); you have to define callback function that will be executed when the server responds with the data, otherwise you are trying to access empty data.
    The code would look something like this:

    var xmlhttp = new window.XMLHttpRequest();
    xmlhttp.open("GET", "xmlfile.xml");
    xmlhttp.send(null);
    xmlhttp.onreadystatechange = callbackFunction;
    
    
    
    function callbackFunction(){
      if (xmlhttp.readyState == 4){
         xml = xmlhttp.responseXML.documentElement; 
        var thegroup = xml.getElementsByTagName('group')[0];
        if (!group) {
          alert('No <group> in the XML: ' + xml);
          return;
        } else {
          alert(xml + 'have a <group> tag');
        }
      }
    }
    

    this way, you are using onReadyStateChange to tell the browser to run callbackFunction everytime the server sends back a response. It tests for the readyState to be 4 which means that the request has been completely served.

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

Sidebar

Related Questions

I want use html5's new tag to play a wav file (currently only supported
In my XML file chapters tag has more chapter tag.i need to display chapters
I have just tried to save a simple *.rtf file with some websites and
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I have an MVC Razor view @{ ViewBag.Title = Index; var c = (char)146;
I have a reasonable size flat file database of text documents mostly saved in
I'm parsing an XML file, the creators of it stuck in a bunch social
I am trying to loop through a bunch of documents I have to put
I am trying to understand how to use SyndicationItem to display feed which is

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.