I am using the node package xml-js to convert a SOAP response to json.
The text element response I got in two different requests are detailed below.
How do I change the response in each cases?
1. Response
{
"declaration": {
"attributes": {
"version": "1.0",
"encoding": "utf-8"
}
},
"elements": [
{
"type": "element",
"name": "Envelope",
"attributes": {
"xmlns:soap": "http://schemas.xmlsoap.org/soap/envelope/",
"xmlns:xsi": "http://www.w3.org/2001/XMLSchema-instance",
"xmlns:xsd": "http://www.w3.org/2001/XMLSchema"
},
"elements": [
{
"type": "element",
"name": "Body",
"elements": [
{
"type": "element",
"name": "FetchCustResponse",
"attributes": {
"xmlns": "http://DC_API/vproxy/"
},
"elements": [
{
"type": "element",
"name": "FetchCustResult",
"elements": [
{
"type": "text",
"text": "00_AccountNo: 242734005790, AccountType: 1, Address: Cell:340397882, Balance: 0.00, ContactNo: Cell:01039788200, MeterNo: 11178005790, MinAmount: 11,715.40, Name: David James"
}
]
}
]
}
]
}
]
}
]
}
Desired output for the text element value
"text" : {
"AccountNo": "04278005790",
"AccountType": "1",
"Address": "08039788217",
"Balance": "0.00",
"ContactNo": "08039788217",
"MeterNo": "04278005790",
"MinAmount": "11,715.40",
"Name": "David James"
}
2.
Response
{
"declaration": {
"attributes": {
"version": "1.0",
"encoding": "utf-8"
}
},
"elements": [
{
"type": "element",
"name": "Envelope",
"attributes": {
"xmlns:soap": "http://schemas.xmlsoap.org/soap/envelope/",
"xmlns:xsi": "http://www.w3.org/2001/XMLSchema-instance",
"xmlns:xsd": "http://www.w3.org/2001/XMLSchema"
},
"elements": [
{
"type": "element",
"name": "Body",
"elements": [
{
"type": "element",
"name": "FetchUsageResponse",
"attributes": {
"xmlns": "http://DC_API/vproxy/"
},
"elements": [
{
"type": "element",
"name": "FetchUsageResult",
"elements": [
{
"type": "text",
"text": "00_<NewDataSet>\r\n <Table>\r\n <ID>9872686</ID>\r\n <AccountNo>04278005790</AccountNo>\r\n <MeterNo>90278005790</MeterNo>\r\n <AccounType>1</AccounType>\r\n <PINs>5539</PINs>\r\n <TotalAmount>4900.00</TotalAmount>\r\n <CreditedAmount>4802.00</CreditedAmount>\r\n <FleetComm>9.80</FleetComm>\r\n <DealerComm>73.50</DealerComm>\r\n <BankComm>14.70</BankComm>\r\n <Date>2021-04-24T16:32:36.4+01:00</Date>\r\n <IDWebTrans>13385836</IDWebTrans>\r\n <NoOfCards>1</NoOfCards>\r\n <BUID>12</BUID>\r\n <TxnReference>BD069419</TxnReference>\r\n <Token>24559787672457451531</Token>\r\n <TokeUnit>195.70</TokeUnit>\r\n <TokenAmt>4558.14</TokenAmt>\r\n <Charges>341.86</Charges>\r\n </Table>\r\n <Table>\r\n <ID>9763409</ID>\r\n <AccountNo>04278005790</AccountNo>\r\n <MeterNo>90278005790</MeterNo>\r\n <AccounType>1</AccounType>\r\n <PINs>5539</PINs>\r\n <TotalAmount>5000.00</TotalAmount>\r\n <CreditedAmount>4900.00</CreditedAmount>\r\n <FleetComm>10.00</FleetComm>\r\n <DealerComm>75.00</DealerComm>\r\n <BankComm>15.00</BankComm>\r\n <Date>2021-04-06T12:35:17.367+01:00</Date>\r\n <IDWebTrans>13270588</IDWebTrans>\r\n <NoOfCards>1</NoOfCards>\r\n <BUID>12</BUID>\r\n <TxnReference>108969129</TxnReference>\r\n <Token>17218654018179855270</Token>\r\n <TokeUnit>118.40</TokeUnit>\r\n <TokenAmt>2520.93</TokenAmt>\r\n <Charges>2479.07</Charges>\r\n </Table>\r\n</NewDataSet>"
}
]
}
]
}
]
}
]
}
]
}
Desired output for the text element value
Array of Objects
Any pointer, solutions or hints, please?
For the first problem, I wrote a function and it is working so far.