Store the label's value as a JSON object in JavaScript

I've encountered a recurring question with no satisfactory answers. Can someone please clarify things for me?

Let's take a look at a JSON file:

{ 'soapenv:Envelope':
   { '$':
      { 'xmlns:soapenv': 'http://schemas.xmlsoap.org/soap/envelope/',
        'xmlns:xsd': 'http://www.w3.org/2001/XMLSchema',
        'xmlns:xsi': 'http://www.w3.org/2001/XMLSchema-instance' },
     'soapenv:Body':
      [ { 'ns1:getTBTransactionsWithFiltersResponse':
           [ { '$':
                { 'soapenv:encodingStyle': 'http://schemas.xmlsoap.org/soap/encoding/',
                  'xmlns:ns1': 'http://TransactionSOAPService/' },
               getTBTransactionsWithFiltersReturn:
                [ { '$':
                     { 'soapenc:arrayType': 'ns2:BeanTBTransaction[1]',
                       'xsi:type': 'soapenc:Array',
                       'xmlns:ns2': 'http://TransactionSOAPService.SOAP.genSrv.tt.slb.com',
                       'xmlns:soapenc': 'http://schemas.xmlsoap.org/soap/encoding/' },
                    getTBTransactionsWithFiltersReturn: [ { '$': { href: '#id0' } } ] } ] } ],
          multiRef:
           [ { '$':
                { id: 'id0',
                  'soapenc:root': '0',
                  'soapenv:encodingStyle': 'http://schemas.xmlsoap.org/soap/encoding/',
                  'xsi:type': 'ns3:BeanTBTransaction',
                  'xmlns:soapenc': 'http://schemas.xmlsoap.org/soap/encoding/',
                  'xmlns:ns3': 'http://TransactionSOAPService.SOAP.genSrv.tt.slb.com' },
               batchId: [ { _: '36', '$': { 'xsi:type': 'xsd:int' } } ],
               ... (truncated for brevity) ... ] } ] } }

I'm interested in extracting the alphanumId label values and saving them into a variable.

Is there a method to retrieve these label values effectively, considering there could be multiple instances?

Ultimately, I aim to export these values into a CSV file.

Answer №1

After much searching, I finally discovered the answer:

const ast = XmlReader.parseSync(xml);

const x =xmlQuery(ast).find('alphanumId').text();

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

Next.js server component allows for the modification of search parameters without causing a re-fetch of the data

I have a situation where I need to store form values in the URL to prevent data loss when the page is accidentally refreshed. Here's how I am currently handling it: // Form.tsx "use client" export default function Form(){ const pathname ...

Incorporate text into the URL of the image

Got a URL of an image like this: https://lipsum.mobi/catalog/product/SE0229E/YG/AAA/4/1/SE0229E-YG-AAA-4.jpg', and looking to add 240x240 within the URL. Current Url: https://lipsum.mobi/catalog/product/SE0229E/YG/AAA/4/1/SE0229E-YG-AAA-4.jpg Desire ...

magnificPopup experiencing difficulties when attempting to invoke a class that is dynamically generated within the HTML document

Currently, I am encountering an issue with the magnificPopup. Whenever I try to trigger the popup using the class 'popup-with-zoom-anim', it doesn't seem to work as expected. Has anyone else faced a similar problem before? <body> < ...

Steps for sending data to a modal window

Consider this scenario: I have a function that retrieves some ids, and I utilize the following code to delete the corresponding posts: onClick={() => { Delete(idvalue[i]) }} Nevertheless, I am in need of a modal confirmation before proceeding with the ...

Unable to locate module named "Gulp"

When attempting to run npm start, I encounter the following error message: module.js:545 throw err; ^ Error: Cannot find module './Gulp' at Function.Module._resolveFilename (module.js:543:15) at Function.Module._load (module.js:470:25) at Modul ...

The state returned by React Redux does not meet the expected results

I recently implemented a like function on the backend using Node and MongoDB. This function successfully returns the post with an updated likes counter, which I tested using Postman. The post object contains properties such as likes, _id, by, createdAt, an ...

Refresh the content of VueJS Resource

Resource file helper/json_new.json { "content": { "content_body": "<a href='#' v-on:click.prevent='getLink'>{{ button }}</a>", "content_nav": "", } } Vue script.js file new Vue({ el: 'body', ...

Utilize the Spotify API to discover tracks by including the album title and artist's name in the search

Currently working on a project that involves searching for a music track on Spotify. The idea is to input the track name in the text area and generate a list of matching Track IDs along with Artist Names, Album Names, and Artwork. I have made some progress ...

Exploring YouTube API V3 Playback Limitations in PHP

After using YouTube API V2 until last week, I decided to upgrade my functions to V3 due to quota reasons. The API is being utilized on a website called www.gumdust.com for sharing videos from YouTube and checking daily if the shared videos are still availa ...

Tips for bypassing an argument using the POST method in NodeJS

Hey there! I started off by creating a question about passing over data using the GET method, but now I'm facing a new problem when trying to pass over data with the POST method. Below is my code snippet where things seem to be going wrong. My goal is ...

Creating a conditional statement in jQuery that will append text to a specific DIV element after a form has been successfully

I currently have a form set up that is functioning properly, but I am looking to make some changes. Instead of redirecting the user to a new page with a success message upon submitting the form, I want the success message to be displayed in a div next to t ...

"Utilizing Ramda's map function to integrate dynamic keys: A step-by-step guide

I am currently working with an array structured like this : array = ['2020-06-03', '2020-06-05', '2020-06-06'] My task is to transform it into the following format : Object { "2020-06-03": Object { "selec ...

Remove multiselect label in PrimeNG

I am attempting to change the multiselect label of selected items and replace it with a static default label. Here is what it currently shows: https://i.sstatic.net/qBNHG.png This is what I have tried: .p-multiselect-label { visibility: collapse; ...

Can you guide me on implementing first-person controls in react-three-fiber?

I'm attempting to set up a scenario where the camera remains stationary while allowing users to rotate the view around either the y or x axis by dragging their mouse. I'm looking for something akin to the functionality seen on threejs.org/example ...

Tips for eliminating the gap between Bootstrap 4 columns

Is there a way to eliminate the spacing between Bootstrap columns? I have three columns set up using Bootstrap but no matter what I do, I can't seem to get rid of the space between them. <!doctype html> <html lang="en> <head> ...

Having trouble getting OrbitControls to function properly in Object-Oriented Programming (OOP)

Exploring the world of THREE.js and Object-oriented JavaScript. Here's the code I'm working with: https://gist.github.com/BobWassermann/581492be11db361c39ee While my browser is showing the correct output, I'm having trouble getting the Orb ...

Exploring the process of extracting a JSON array from HttpServletRequest

I am completely new to servlets and I'm having trouble extracting a JSON array from the HttpServletRequest This is the JSON data I'm sending to Java: page: 1 start: 0 limit: 20 sort: [{"property":"fiscalYear","direction":"DESC"}] protected vo ...

Transform the output of a MySQL query into a specific JSON format using PHP

My table contains data stored in the following JSON format: https://i.stack.imgur.com/Ab5ug.png The JSON result obtained from a query is as follows: [{ "cnt": "1", "category_name": "Entertainment", "event_name": "Typhoon Sample", "year_o ...

Render and download the file concurrently while displaying the view in Express

I'm looking to accomplish a task in Express where I can render a file and download it simultaneously. My current code looks like this: res.attachment('filename.csv'); res.render('pages/result', { data }); However, with this setu ...

The feature of Access Control Request Headers involves appending certain information to the header of an AJAX request when using jQuery

Looking to enhance an AJAX POST request from jQuery with a custom header. Attempted solution: $.ajax({ type: 'POST', url: url, headers: { "My-First-Header":"first value", "My-Second-Header":"second value" } ...