Retrieving the value of a particular child element using XML/AJAX

I've encountered an issue with ajax and xml. I have an xml file that contains the status of multiple buttons. In my webpage, I need to determine the current status of each button. Here's a snippet from the xml file:

<?xml version="1.0" encoding="utf-8"?>
<btn_status>
    <btn1>
        <titel>Button 1</titel>
        <status>inactive</status>
    </btn1>

    <btn2>
        <titel>Button 2</titel>
        <status>active</status>
    </btn2>

</btn_status>

Here is a portion of my ajax script:

document.write("<p>Button Status</p>");
document.write("<table border='1'>");
var xmlContent=xmlDoc.getElementsByTagName("btn1");
for (i=0;i<xmlContent.length;i++)
  {
  document.write("<tr><td>");
  document.write(xmlContent[i].getElementsByTagName("titel")[0].childNodes[0].nodeValue);
  document.write("</td><td>");
  document.write(xmlContent[i].getElementsByTagName("status")[0].childNodes[0].nodeValue );
    if(btnStatus1=xmlDoc.getElementsByTagName("status")[0].childNodes[0].nodeValue == 'active'){
      document.write("<img src='Normal.png' />");
    }
      else  // ie5/6
  {
      document.write("<img src='error.png' />");
  }
    document.write("</td></tr>");
  }

The challenge I'm facing is that the if/else statement only addresses the status of btn1. I'm unsure how to query the status of btn2 and subsequent buttons. Something like

btnStatus2=btn2.status...

Any ideas on how to approach this?

Answer №1

Apologies for the confusion, I managed to resolve the issue on my own by simply counting towards the child elements...

if(btnStatus2=xmlDoc.getElementsByTagName("status")[1].childNodes[0].nodeValue == 'active'){
      document.write("<img src='Normal.png' />");
    }
      else  // ie5/6
  {
      document.write("<img src='error.png' />");
  }
    document.write("</td></tr>");
  }

As for the third entry:

var xmlContent=xmlDoc.getElementsByTagName("btn3");
for (i=0;i<xmlContent.length;i++)
  {
  document.write("<tr><td>");
  document.write(xmlContent[i].getElementsByTagName("titel")[0].childNodes[0].nodeValue);
  document.write("</td><td>");
  document.write(xmlContent[i].getElementsByTagName("status")[0].childNodes[0].nodeValue );
    if(btnStatus3=xmlDoc.getElementsByTagName("status")[2].childNodes[0].nodeValue == 'active'){
      document.write("<img src='Normal.png' />");
    }
      else  // ie5/6
  {
      document.write("<img src='error.png' />");
  }
    document.write("</td></tr>");
  }

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Confirm the value of $index and apply a specific style

Trying to figure out how to highlight a table row using AngularJS within a directive. Here is some pseudo code I came up with: if(highlight.indexOf($index) != -1) set .highlight css class Below is an example of my code snippet: $scope.highlight = [0, ...

Is there a way to customize the progress bar percentage in Ant design?

I am currently utilizing React JS and importing the Ant Design progress component (refer to https://ant.design/components/progress/). However, I am facing difficulties in dynamically editing the percentage of the progress bar using JavaScript after it has ...

Modify the Viewbox to encompass an svg component

Currently, I am working on creating a map using SVG where users can zoom into a specific area within the SVG, such as a state or country. I came across a helpful tutorial that demonstrates this functionality along with animation. The tutorial can be found ...

Automating the Process of File Downloads Using Ajax and PHP

I am currently working on a form that requires users to enter a secret key. Once the key is submitted, it is verified against a database. If the key is found, the relevant file associated with the key should be downloaded automatically. I have successfully ...

Effortlessly verify checkboxes associated with the corresponding ID in the database

I am currently facing a challenge while working on a project using Codeigniter that I need help resolving. Here is the issue: In the view above, you can see multiple roles and permissions displayed. Each role has its own set of permissions stored in the ...

Creating an HTML Form that Sends an Email

I'm completely stumped as to where the issue lies! The mail() function is working perfectly fine (I tested it with a simple PHP file), but for some reason, my form isn't sending any emails! HTML <section id="contact"> <div id="go ...

Discovering the following div

<button class="volumen-btn" onclick="niceFunction()> <i class="fa fa-volume-up"></i> </button> <div class="volume-control-container" id="container1" style="display:none;"> <input type="range" name="blabla" class="volume-ran ...

AngularJS Uncaught ReferenceError: variable is not

I am facing an issue where I cannot retrieve a value from a function. I am performing REST requests for testing purposes and when trying to get a date, it always returns undefined. An Illustration $http.get('app/components/home/controller/test_calen ...

The simplest method to retrieve Json or a Collection using Meteor's Iron Router

Currently, I am in the process of creating a set of routes. Below are some examples: / - This route should render the home page template /items - This route should display the items page template /items/weeARXpqqTFQRg275 - This route is set to return an ...

The Android material design concept does not incorporate rounded corners in the cardview feature on mobile devices

I am facing an issue with Cardview in Android X. <androidx.cardview.widget.CardView android:id="@+id/card_box_register" android:layout_width="match_parent" android:layout_height=" ...

AngularJS synchronous $resource functionality allows for the ability to make parallel API

I'm facing a dilemma because I understand that Javascript isn't designed for synchronous work, especially in the case of AngularJS. However, I find myself in a situation where I require it. The main page on the "www" domain (built with AngularJS ...

Exploring the process of transferring a jQuery array from a Rails controller to a PostgreSQL array column

For my project, I successfully pass a JavaScript array to a Rails controller using AJAX. The JavaScript array consists of upload image names. Within my postgresql database, there is an array column called "images." In the Rails controller, I attempted the ...

Retrieve JSON data within React without the need for importing it

Recently, I've been incorporating data from a JSON file into a React component in a unique way: import data from '../../public/json/data.json'; Using the innovative create-react-app tool, upon running npm run build, the expected behavior o ...

The Angular application fails to refresh the UI after receiving new data updates

Currently pursuing my master's degree and encountering a bug that I believe should have an easy fix, but I'm struggling to figure it out. My project involves Angular, Firestore, and RxJs. The main issue is that the UI does not update as expected. ...

Retrieving and showcasing XML data in JavaScript

I have a string that has been parsed from an XML page: var data = '<Message>Fermata 1431 - Linea 202 -> 08:57 Linea 201 -> 09:02 Linea 256B -> 09:02 Linea 202 -> 09:05 Linea R2 -> 09:06 Linea 201 -> 09:13 Linea 201 -> 09:18 ...

Differences in font size of Text Sprites between ThreeJS's WebGL renderer and Canvas renderer

I am currently working with Three JS to develop a 3D graph and I am facing an issue with displaying units of the graph as THREE.SPRITE. To create a SPRITE, I first generate a canvas element and add text to it. Then I proceed to create a THREE.Texture using ...

Transition between different segments

Currently working on a sapui5 fiori app, I find myself utilizing multiple fragments based on the mode (read, create, edit). However, I am stuck on how to smoothly navigate from one fragment to another, and more importantly, how to seamlessly return to th ...

Steps for updating inputs using a modal selection

I am currently utilizing the Laravel Framework and facing an issue where I need to allow users to choose a specific event to edit if they have multiple event records. I have already implemented a modal that displays all the events, but I am unsure how to c ...

"Step-by-step guide on adding a new row to a table using a child controller in AngularJS

I have a table where I can insert new rows by opening a dialog window and entering the data. The dialog window contains a child controller called addNewTaskCtrl. Inside this dialog, there is a form that inserts data into the table when the "Add" button is ...

Is it possible to trigger an AJAX request twice?

<table><form action="/roulette.php" name="ismForm" method="get"> <select id="selez3c" name="bet3c" size="1" class="selezionev" > <option value="0.50">$0.50</option> <option value="0.75"& ...