Analyzing XML markers

Extracting specific values from XML tags

We are looking to extract and display only the tags that contain the words "sports" and "secure" within the

<str name="word">WORD</str>
tag in the following XML:

XML

<response>
    <lst name = "responseHeader">
        <int name status>0</int>
        <int name QTime>3</int>
    </lst>
    <result name="response",numFound="0",start="0"/>
    <lst name="spellcheck">
      <lst name="suggestions">
        <lst name="sporsts">
          <int name="numFound">1</int>
          <int name="startOffset">0</int>
          <int name="endOffset">5</int>
          <int name="origFreq">0</int>
          <arr name="suggestion">
            <lst>
              <str name="word">sports</str>
              <int name="freq">1</int>
            </lst>
          </arr>
        </lst>
        <lst name="secuer">
          <int name="numFound">1</int>
          <int name="startOffset">6</int>
          <int name="endOffset">17</int>
          <int name="origFreq">0</int>
          <arr name="suggestion">
            <lst>
              <str name="word">secure</str>
              <int name="freq">1</int>
            </lst>
          </arr>
        </lst>
      </lst>
      <bool name="correctlySpelled">false</bool>
    </lst>
</response>

We are currently using AJAX to retrieve this data. The AJAX call is as follows:

$.ajax({
   type: "GET",
   url: solrurl,
   dataType: "xml",
   cache: false,
   success: function(data) {
        console.log(data);
         },      
     error : function(data)
     { 
          alert(Contact the Solr Admin);
     }
});

We attempted to access the data using response.spellcheck.suggestions[0], but encountered errors. We tried different parameters without success!

Any suggestions on how we can specifically extract and store the words "sports" and "secure" into an array would be greatly appreciated.

Answer №1

Your code has been successfully updated and tested, confirming its functionality.

JAVASCRIPT

$(document).ready(function () {
    var Values = new Array();
    $.get("checkvariables.php",{},function(xml){
        $("item",xml).each(function(i){
            Values.push($(this).text());
        });
        console.log(Values)
    });
});

You can view the results in the browser's console window:

["sports", "secure"]

I trust this meets your expectations for the task at hand.

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

Showing an image stored in an array using JavaScript

This script is designed to pull images from a specific location on an HTML page. images = new Array(); images[0] = new Image(); images[0].src = "images/kate.jpg"; images[1] = new Image(); images[1].src = "images/mila.jpg"; document.write(images[0]); I&a ...

Tips for applying an active class to buttons using ng-click?

Here is the HTML code for the buttons. The taskfilter is the filter that controls how the buttons work when clicked and the class name is 'sel' <a class="clear-completed" ng-click="taskfilter = 1" ng-class="{'sel':enabled}"> &l ...

`I'm having difficulty transferring the project to Typescript paths`

I posted a question earlier today about using paths in TypeScript. Now I'm attempting to apply this specific project utilizing that method. My first step is cloning it: git clone <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cf ...

How can you use JQuery to assign a single function as an onClick handler for multiple radio buttons?

I have a custom function named handleOnClickRadio(i, j);, and multiple radio buttons with the IDs in the format of id="something-radio[i][j]". These radio buttons are all contained within a table labeled "bigtable". Is there a way to link the function han ...

Dynamic content being added and modified using Ajax on a webpage

Trying to integrate Ajax requests into my Rails 3 app has been a challenging experience. Despite spending days following various online tutorials, the only successful outcome I've achieved so far is with Ajax delete. On my site, users have a profile ...

Passing and removing array parameters in HTTP requests using Angular

I have an Array of statuses objects. Each status has a name and a boolean set to false by default. These represent checkboxes in a form with filters - when a checkbox is checked, the boolean value is set to true: const filters.statuses = [ { name ...

Looking for a method to substitute "test" with a different value

Showing a section of the menu using <li id="userInfo" role="presentation" data-toggle="tab" class="dropdown"> <a href="#" name="usernameMenu" class="dropdown-toggle" data-toggle="dropdown" role="button"> <span class="glyphicon glyph ...

Functionality issue with Datatables within JQuery-UI Tabs

I'm experiencing an issue with the compatibility of jQuery-UI tabs and Datatables. My goal is to create a scrollable table that displays information fetched from a database. Upon initially loading the page, the table appears like this. It looks like ...

AngularJS directive does not trigger when switching tabs or scrolling pages

I came across a solution to display a placeholder image before the real image fully loads while browsing online here. I implemented the code provided in the accepted answer on my page, where I have two tabs using `ion-slide-box` for tab selection. Each tab ...

ng-bind-html is having trouble parsing the HTML correctly and binding it

Here is the code for my controller: myApp.controller('actionEditController', ['$scope', '$stateParams', '$sce',function ($scope, $stateParams, $sce) { $scope.table="<p>OOPSY</p>"; $sc ...

Generate Bootstrap 5 Navbar <li> and <ul dropdown item> dynamically using JavaScript

Requesting assistance I have stored text in the constant.js file as shown below. export const navLinks = [ { id: "manage", title: "Manage", }, { id: "transactions", title: "Tran ...

Is there a way to conditionally redirect to a specific page using NextAuth?

My website has 2 points of user login: one is through my app and the other is via a link on a third-party site. If a user comes from the third-party site, they should be redirected back to it. The only method I can come up with to distinguish if a user is ...

Enhancing password security with an Ajax form field

Looking for an ajax/javascript plugin that adds color indicators next to password fields, with each password having its own unique color combination. ...

Use Material UI Grid to create a horizontal line design instead of focusing on making the

Is there a way to turn off responsiveness for the material UI grid similar to how it can be done with a basic HTML table? While an HTML table scales down and adds a horizontal scroll bar, the material UI grid remains responsive as shown in the example belo ...

Boosting numbers using ajax in combination with PHP and MySQL

My requirement is for it to fit in and when I click on a file, the number should increase to 1 and be saved in the database. I have already set up the database and have part of the AJAX code ready. The issue is that when the number increments, the page up ...

Add-on or code snippet for Node.js that allows for optional regex groups

Strings in Sequence line 1 = [A B C] line 2 = [A C] line 3 = [B C] Regular Expression /\[?(?<groupA>[A])?(?:[ ]*)?(?<groupB>[B])?(?:[ ]*)?(?<groupC>[C])\]/gm Is there a way to achieve the desired output using a plugin or spe ...

Using AJAX and Perl to dynamically update HTML content

Currently, I am attempting to dynamically update a div on my website using ajax and perl. The current implementation I have sort of works but needs improvement. HTML: <h2 id="cpu">--</h2> JS/ajax call: $.ajax({ type: 'GET&apos ...

Creating customizable Isotope objects using custom CSS margins that are influenced by the child-nth selector and JavaScript

My recent project involved creating a simple .isotope gallery, and when viewing the selected #portfolio-wrap container in Chrome Dev Tools, here is how it appears: Unfortunately, I am unable to upload three links here. Please visit this link for more info ...

Invoke cloud functions independently of waiting for a response

Attempting a clever workaround with cloud functions, but struggling to pinpoint the problem. Currently utilizing now.sh for hosting serverless functions and aiming to invoke one function from another. Let's assume there are two functions defined, fet ...

Troubleshooting ng-class functionality in AngularJS

I am attempting to utilize AngularJS in order to change the class name of a div element. Despite following the guidance provided in this answer, I am encountering difficulties as the class name is not updating in my view. Below is the code from my view: ...