Transforming XML to JSON with Script mediator in WSO2 Enterprise Service Bus

Trying to process the response from WSO2 ESB and DDS API, which is currently in XML format. How can I convert this response to JSON format with some modifications using a script mediator?

<?xml version='1.0' encoding='UTF-8'?><soapenv:Envelopexmlns:soapenv="http://www.w3.org/2003/05/soap-envelope"><soapenv:Body>
<employeeCollection xmlns="http://employee.us.wso2.com">
    <employee>
        <EmployeeID>17</EmployeeID>
        <FirstName>jak</FirstName>
        <LastName>123</LastName>
        <Team>ok</Team>
    </employee>
    <employee>
        <EmployeeID>18</EmployeeID>
        <FirstName>jak</FirstName>
        <LastName>123</LastName>
        <Team>ok</Team>
    </employee>
    <employee>
        <EmployeeID>19</EmployeeID>
        <FirstName>jak</FirstName>
        <LastName>123</LastName>
        <Team>ok</Team>
    </employee>
</employeeCollection>

Desiring the output as shown below:

{  "status": "success",
    "employee": [
      {
        "EmployeeID": 17,
        "FirstName": "jak",
        "LastName": 123,
        "Team": "ok"
      },
      {
        "EmployeeID": 18,
        "FirstName": "jak",
        "LastName": 123,
        "Team": "ok"
      },
      {
        "EmployeeID": 19,
        "FirstName": "jak",
        "LastName": 123,
        "Team": "ok"
      }]
}

Answer №1

Here are some resources you can check out:

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

Having issues with uploading an .xml file using PHP

As I work on creating a form that allows users to upload XML files to my server, with the intention of overwriting existing ones, I encountered a hurdle. The current code in use does not facilitate uploading if the file already exists, but that's some ...

Revolutionizing messaging with Vue JS and Firebase

My web application is designed to check if a user has messages in the Firebase database. If messages are found, it retrieves the data from the users who sent those messages from my local database and displays them in a list using a v-for loop. The display ...

A dynamic display featuring four columns that showcase unique content every day of the week

As a beginner in coding, I am attempting to design a page with 4 columns that will showcase different titles and descriptions each day of the week. My goal is to have a set of titles and descriptions displayed on Monday, a different set on Tuesday, and so ...

Retrieving data from a JSON object based on a specific key

I am currently struggling to parse the JSON object and it has been quite challenging for me. Here is what I am attempting to achieve: var dat = {array:test}; console.log("testing" + JSON.stringify(dat.array[0])); for(var i = 0; i < dat.array.le ...

What could be causing worker threads to fail when instantiating a class from a separate file?

The following TypeScript file is being used: import { Worker, WorkerOptions, isMainThread, parentPort } from "worker_threads"; import path from "path"; export class SimpleWorker { private worker: any; constructor() { i ...

The issue with ngFileUpload causing empty file posts on Safari

Currently, I am utilizing ngFileUpload to transmit images to the Cloudinary service. My application is constructed on Ionic and is meant to be functional on both iOS and Android platforms. The code snippet below showcases my image uploading process: .se ...

Looking to establish a minimum height for a webpage

I am working on creating a webpage with three distinct sections: A fixed height header A fluid main section A fixed height footer My goal is to ensure that the page has a minimum height so that the bottom of the footer aligns with the bottom of the wind ...

Converting JSON data into a Backbone Model

My current project involves utilizing backbone.js, and I have encountered a json data structure as follows: { first_name: 'David', last_name: 'Smith', family: [{father: 'David', mother: 'Rose', brother: ...

React Native: Picker value remains static

I'm encountering an issue where the value of the picker does not change when I select a new value from it. This problem started occurring after I added the onValueChange function. If anyone has any insights or suggestions on how to resolve this, I wou ...

Creating a new row at the end of a table dynamically through the onblur event in Javascript, without the need for a button

I need assistance with a table that has 3 columns and 5 rows. I want to dynamically add a new row after the last row when using the last row, and continue this process for each newly created row without having to use buttons. The solution should involve ...

Transferring information in JSON format from an API to a JavaScript variable

Hi there, I'm new to json/javascript so your patience is appreciated. I am receiving json data from an API URL that looks like this: { "employees": [ { "firstName":"John" , "lastName":"Doe" }, { "firstName":"Anna" , "lastName":"Smith" }, { "firstN ...

Is it possible to pass a service into another service in AngularJS?

I'm currently working on figuring out the best method for this task: Our backend developer has requested a json file that contains a master list of api urls used in requests by my frontend. This will ensure that the end user's browser only needs ...

Leveraging javascript to extract data from several input fields and dynamically incorporate them into a table

I'm currently in the process of developing a script that extracts field values and organizes them into a table for verification purposes. The challenge I face is that users have the ability to add multiple fields (up to 5), each with its own unique id ...

Guide for filtering MongoDB results in 15-minute intervals based on timestamp input

I'm faced with a seemingly "simple" issue, but my solution feels unnecessarily complex and I'm struggling to implement it... This is the schema I'm working with: const DensitySchema = mongoose.Schema( { map_id: mongoose.Schema.Types. ...

Ways to refresh a nested form

I'm currently learning Ruby on Rails and working on developing a web application. The app consists of a classic model with Users who can create Posts. Another model called Online is used to display the posts on a common wall, and it has an associatio ...

The steps to triggering a button click after e.preventDefault()

When attempting to prevent a click() event of a button by using preventDefault() after unbinding the button with unbind(), I encountered an issue where it did not work as expected. <script> $("#update2FAButton").on("click",function(e){ e.pre ...

I need help figuring out how to get a horizontal scrollbar positioned at the top of a div to function properly once the content has been loaded using ajax

HTML CODE <div id="scrollidout" style="overflow: auto; overflow-y: hidden; "> <div id="scrollidin" style="padding-top: 1px; height: 20px; width: 1000px">&nbsp;</div> </div> <div class="resultcontent" style="overflow ...

Incorporating User Input: Adding Paragraph Elements with HTML and Javascript to a Div Container

I am attempting to test my ability by creating a basic webpage. My goal is to take the text entered by the user in a textarea and add it to the page using a button. This button should generate a new paragraph element, place the user input inside of it, and ...

Tips for managing NaN values within mathjs.evaluate

console.log(mathjs.evaluate("(goodCount/(goodCount+reject_count))>0.99", { goodCount: 0, reject_count: 0, Total_Planned_time: 10 })) I am facing an issue where if both goodCount and reject_count are zero, this function returns NaN. Howe ...

Can you explain how this particular web service uses JSON to display slide images?

{ "gallery_images": [ {"img":"http://www.jcwholesale.co.uk/slider_img/big/1_1433518577.jpg"}, {"img":"http://www.jcwholesale.co.uk/slider_img/big/1_1433519494.jpg"}, {"img":"http://www.jcwholesale.co.uk/slider_img ...