If you set the xplicitArray option to false, when it parses it won't create those arrays where you didn't expect. Like this:

function parseBody(body) {
    var parseString = require('xml2js').parseString;

    const options = {
        explicitArray: false
    };

    var xml = body
    parseString(xml, options, function (err, result) {
        console.log("cust fname: " + result['soapenv:Envelope']['soapenv:Body']['int:readResponse']['response']['cust']['fName']);
    })
}
var input = '<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:int=\"realURLHere"><soapenv:Header/><soapenv:Body><int:readResponse><response><request>?</request><cust><fName>?</fName></cust></response></int:readResponse></soapenv:Body></soapenv:Envelope>';
parseBody(input);

Furthermore if you remove the prefixes it can get even cleaner:

function parseBody(body) {
    var parseString = require('xml2js').parseString;
    var stripNS = require('xml2js').processors.stripPrefix;

    const options = {
        tagNameProcessors: [stripNS],
        explicitArray: false
    };

    var xml = body
    parseString(xml, options, function (err, result) {
        console.log("cust fname: " + result.Envelope.Body.readResponse.response.cust.fName);
    })
}
var input = '<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:int=\"realURLHere"><soapenv:Header/><soapenv:Body><int:readResponse><response><request>?</request><cust><fName>?</fName></cust></response></int:readResponse></soapenv:Body></soapenv:Envelope>';
parseBody(input);```
Answer from Marc Pereira on Stack Overflow
🌐
npm
npmjs.com › package › xml2js
xml2js - npm
Simple XML to JavaScript object converter.. Latest version: 0.6.2, last published: 3 years ago. Start using xml2js in your project by running `npm i xml2js`. There are 10737 other projects in the npm registry using xml2js.
      » npm install xml2js
    
Published   Jul 26, 2023
Version   0.6.2
Author   Marek Kubica
🌐
IronPDF
ironpdf.com › ironpdf for node.js › ironpdf for node.js blog › node help › xml2js npm
xml2js npm (How It Works For Developers)
June 23, 2025 - A Node.js package called XML2JS makes it easier to parse and create a simple XML (Extensible Markup Language) to JavaScript object converter
Discussions

node.js - Parsing with xml2js - Stack Overflow
I am new to node.js and need to parse XML. In js, I just use a DOMParser and use getElementsByTagName to get the values I desire. I have just switched to node and am using xml2js (willing to consider More on stackoverflow.com
🌐 stackoverflow.com
Using xml2js gives me an odd result
I’m using the xml2js library but seem to be getting an odd console log which looks like it may be proxy information instead of the actual XML response (which is returned correctly). I’m not using a proxy. Console Log looks like this Feeling a bit bewildered but very open to the possibility ... More on community.postman.com
🌐 community.postman.com
0
0
July 4, 2025
[RC0] How to import "xml2js"
After RC0 upgrade the xml2js import failed : npm install xml2js --save npm install @types/xml2js --save --save-exact the code : import xml2js from "xml2js"; @Injectable() export class XMLDataService { construct… More on forum.ionicframework.com
🌐 forum.ionicframework.com
1
0
September 30, 2016
Having difficulty with xml2js on Xml->Json->Xml in NodeJS
You're passing stringified JSON back into the buildObject() function and not a javascript object. After your .replace() call you should do a JSON.parse() before passing it into buildObject(). Also, your .replace() will only replace the first instance of "Hello" and not all instances of it. You should use a global regex instead: var needle = /Hello/g; json = JSON.stringify( json ).replace( needle, "Hellow" ); More on reddit.com
🌐 r/node
7
4
May 2, 2017
🌐
npm
npmjs.com › search
xml2js - npm search
Convert an XML file or XML data to JSON (via xml2js), with promises.
Top answer
1 of 4
4

If you set the xplicitArray option to false, when it parses it won't create those arrays where you didn't expect. Like this:

function parseBody(body) {
    var parseString = require('xml2js').parseString;

    const options = {
        explicitArray: false
    };

    var xml = body
    parseString(xml, options, function (err, result) {
        console.log("cust fname: " + result['soapenv:Envelope']['soapenv:Body']['int:readResponse']['response']['cust']['fName']);
    })
}
var input = '<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:int=\"realURLHere"><soapenv:Header/><soapenv:Body><int:readResponse><response><request>?</request><cust><fName>?</fName></cust></response></int:readResponse></soapenv:Body></soapenv:Envelope>';
parseBody(input);

Furthermore if you remove the prefixes it can get even cleaner:

function parseBody(body) {
    var parseString = require('xml2js').parseString;
    var stripNS = require('xml2js').processors.stripPrefix;

    const options = {
        tagNameProcessors: [stripNS],
        explicitArray: false
    };

    var xml = body
    parseString(xml, options, function (err, result) {
        console.log("cust fname: " + result.Envelope.Body.readResponse.response.cust.fName);
    })
}
var input = '<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:int=\"realURLHere"><soapenv:Header/><soapenv:Body><int:readResponse><response><request>?</request><cust><fName>?</fName></cust></response></int:readResponse></soapenv:Body></soapenv:Envelope>';
parseBody(input);```
2 of 4
2

var custFName = result['soapenv:Envelope']['soapenv:Body'][0]['int:realURLHe‌​re'][0]['response'][‌​0]['cust'][0]['fName‌​'];

This solved my problem. My struggles had to do with this response having everything in an array. If there is an easier way to do this or something more dynamic, please let me know. But for now, this worked.

🌐
CodeSignal
codesignal.com › learn › courses › hierarchical-and-structured-data-formats-1 › lessons › working-with-xml-in-javascript-using-xml2js
Working with XML in JavaScript using xml2js
When xml2js parses XML into a JavaScript object, it converts elements into properties of the object, handling attributes and child elements efficiently. Attributes of an XML element are represented as a separate property named "$" within the object.
Find elsewhere
🌐
Medium
medium.com › @jlicht › effortlessly-parse-and-manipulate-xml-data-in-node-js-with-xml2js-84fc7fa2626b
Effortlessly Parse and Manipulate XML Data in Node.js with xml2js | by Joshua Licht | Medium
March 13, 2023 - If you’ve ever found yourself in this situation xml2js is the perfect solution for you. It allows for you to parse XML and access the data in a straightforward and sensible manner without the need to compile a C parser.
🌐
GitHub
github.com › RikkiGibson › isomorphic-xml2js
RikkiGibson/isomorphic-xml2js: XML parsing for ...
A drop-in replacement for xml2js that uses the built in DOMParser/XMLSerializer when bundled for the browser, drastically reducing the bundle size (~129k for node-xml2js, currently ~6k for isomorphic-xml2js).
Author   RikkiGibson
🌐
GitHub
github.com › vavere › xml2js-parser
GitHub - vavere/xml2js-parser: Simple XML to JavaScript object converter
Simple XML to JavaScript object converter. Contribute to vavere/xml2js-parser development by creating an account on GitHub.
Author   vavere
🌐
Snyk
security.snyk.io › snyk vulnerability database › npm
xml2js vulnerabilities | Snyk
An important project maintenance signal to consider for xml2js is that it hasn't seen any new versions released to npm in the past 12 months, and could be considered as a discontinued project, or that which receives low attention from its maintainers.
🌐
SourceForge
sourceforge.net › projects › xml2js.mirror
xml2js download | SourceForge.net
August 21, 2025 - xml2js is a Node.js module that converts XML into JavaScript objects (and vice versa). It simplifies XML parsing by using pure JavaScript and supports both synchronous and asynchronous parsing.
🌐
Debian
packages.debian.org › sid › node-xml2js
Debian -- Details of package node-xml2js in sid
xml2js parses XML using node-sax and converts it to a plain JavaScript object. Node.js is an event-based server-side javascript engine. dep: node-diff · javascript text differencing implementation · dep: node-sax · event-based streaming XML parser - Node.js module ·
🌐
npm
npmjs.com › package › xml2js-xpath
xml2js-xpath - npm
April 25, 2022 - A library for node-xml2js that allows querying the JSON object with XPath syntax.
      » npm install xml2js-xpath
    
Published   Apr 25, 2022
Version   0.13.0
Author   Dane Summers
🌐
UNPKG
app.unpkg.com › xml2js@0.4.0 › files › README.md
xml2js
Simple XML to JavaScript object converter. ... node-xml2js =========== Ever had the urge to parse XML? And wanted to access the data in some sane, easy way? Don't want to compile a C parser, for whatever reason? Then xml2js is what you're looking for! Description =========== Simple XML to ...
🌐
Postman
community.postman.com › help hub
Using xml2js gives me an odd result - Help Hub - Postman Community
July 4, 2025 - I’m using the xml2js library but seem to be getting an odd console log which looks like it may be proxy information instead of the actual XML response (which is returned correctly). I’m not using a proxy. Console Log looks like this Feeling a bit bewildered but very open to the possibility ...
🌐
Qite
nuget.qite.be › feeds › NPM › xml2js › versions
xml2js Versions
To install xml2js, run the following command after configuring npm:npm install xml2js@0.6.2 · To install xml2js, run the following command after configuring npm:yarn add xml2js@0.6.2 · Install with npm · Add with yarn · configuration help · To install xml2js, run the following command after configuring npm:npm install xml2js@0.4.1-4.1 ·