From 6c9cb2d1efdbb544822af246eb352c2536f1bdc5 Mon Sep 17 00:00:00 2001 From: xWyatt Date: Fri, 15 Jul 2022 14:14:12 -0500 Subject: [PATCH 1/4] docs: suggest to use 'fast-xml-parser' as an XML parser in README Signed-off-by: Wyatt Teeter Signed-off-by: xWyatt --- README.md | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index aa4cf026..9b30d969 100644 --- a/README.md +++ b/README.md @@ -47,11 +47,11 @@ XMLSERVICE will run the command and respond with XML output. ``` -`itoolkit` can run the same CL command with: +`itoolkit`, with the help of an XML parser, can run the same CL command with: ```js const { Connection, CommandCall } = require('itoolkit'); -const { parseString } = require('xml2js'); +const { XMLParser } = require('fast-xml-parser'); const connection = new Connection({ transport: 'ssh', @@ -66,12 +66,11 @@ connection.run((error, xmlOutput) => { if (error) { throw error; } - parseString(xmlOutput, (parseError, result) => { - if (parseError) { - throw parseError; - } - console.log(JSON.stringify(result)); - }); + + const Parser = new XMLParser(); + const result = Parser.parse(xmlOutput); + + console.log(JSON.stringify(result)); }); ``` From d38bcafb3f0784e785e46edbd1e2a1450ab9f101 Mon Sep 17 00:00:00 2001 From: xWyatt Date: Fri, 15 Jul 2022 14:28:18 -0500 Subject: [PATCH 2/4] docs: suggest `fast-xml-parser` to replace `xmlToJson` in migration guide Signed-off-by: Wyatt Teeter Signed-off-by: xWyatt --- docs/migratation-guide-v1.0.rst | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/docs/migratation-guide-v1.0.rst b/docs/migratation-guide-v1.0.rst index 168e2d49..e8a5dc67 100644 --- a/docs/migratation-guide-v1.0.rst +++ b/docs/migratation-guide-v1.0.rst @@ -20,13 +20,13 @@ Sync Mode Operations ``iConn.run()`` no longer supports sync mode. Sync mode is not reccommended and since it did not work properly it was removed. See (`#32 `__) for more details. -``iConn.setTimeout()`` is removed. This function was used to set the timeout for ``iConn.run`` +``iConn.setTimeout()`` is removed. This function was used to set the timeout for ``iConn.run`` sync mode. iSql Authentication ------------------- -``iSql.connect()`` and ``iSql.setOptions()`` are removed. These functions were used in conjunction +``iSql.connect()`` and ``iSql.setOptions()`` are removed. These functions were used in conjunction for XMLSERVICE user authentication. The transports already handle user authentication. @@ -81,8 +81,8 @@ Migrating from ``iConn`` to ``Connection`` passed to their run methods. You cannot simply replace iConn with Connection without adjusting your callbacks. See the :ref:`iconn-to-connection-run` section. -When connecting using idb-connector, ``iConn`` takes 3 arguments: ``database``, ``username``, -and ``password``. These can be passed as attributes on the ``transportOptions`` attribute of the +When connecting using idb-connector, ``iConn`` takes 3 arguments: ``database``, ``username``, +and ``password``. These can be passed as attributes on the ``transportOptions`` attribute of the object passed to ``Connection`` and specify the transport is ``idb``. eg. .. code:: js @@ -95,9 +95,9 @@ object passed to ``Connection`` and specify the transport is ``idb``. eg. }); When connecting using rest, ``iConn`` takes 4 arguments: ``database``, ``username``, ``password``, -and ``options``. The options object included ``host``, ``port``, and ``path`` to -generate the url string. Instead specify ``database``, ``username``, ``password``, and ``url`` -on the ``transportOptions`` attribute of the object passed to ``Connection`` and specify the +and ``options``. The options object included ``host``, ``port``, and ``path`` to +generate the url string. Instead specify ``database``, ``username``, ``password``, and ``url`` +on the ``transportOptions`` attribute of the object passed to ``Connection`` and specify the transport is ``rest``. eg. .. code:: js @@ -292,7 +292,7 @@ xmlToJson --------- ``xmlToJson`` is deprecated and will be removed in ``v2.x``. Use -`xml2js `__ instead. +an external XML parser such as `fast-xml-parser `__. iDataQueue ---------- From 1da5405bb1682d38160d884828e9b46328154d1b Mon Sep 17 00:00:00 2001 From: xWyatt Date: Fri, 15 Jul 2022 14:59:55 -0500 Subject: [PATCH 3/4] docs: `xml2js` -> `fast-xml-parser` for doc examples Signed-off-by: Wyatt Teeter Signed-off-by: xWyatt --- docs/examples/cosine.js | 13 ++++++------- docs/examples/qusrobjd.js | 13 ++++++------- docs/examples/rtvjoba.js | 13 ++++++------- 3 files changed, 18 insertions(+), 21 deletions(-) diff --git a/docs/examples/cosine.js b/docs/examples/cosine.js index 41e2e84e..aaa75479 100644 --- a/docs/examples/cosine.js +++ b/docs/examples/cosine.js @@ -1,5 +1,5 @@ const { Connection, ProgramCall } = require('itoolkit'); -const { parseString } = require('xml2js'); +const { XMLParser } = require('fast-xml-parser'); const conn = new Connection({ transport: 'ssh', @@ -18,10 +18,9 @@ conn.run((error, xmlOutput) => { if (error) { throw error; } - parseString(xmlOutput, (parseError, result) => { - if (parseError) { - throw parseError; - } - console.log(result.myscript.pgm[0].return[0].data[0]._); // 1 - }); + + const Parser = new XMLParser(); + const result = Parser.parse(xmlOutput); + + console.log(result.myscript.pgm.return.data); // 1 }); diff --git a/docs/examples/qusrobjd.js b/docs/examples/qusrobjd.js index bf05209d..f649ea6d 100644 --- a/docs/examples/qusrobjd.js +++ b/docs/examples/qusrobjd.js @@ -1,5 +1,5 @@ const { Connection, ProgramCall } = require('itoolkit'); -const { parseString } = require('xml2js'); +const { XMLParser } = require('fast-xml-parser'); const conn = new Connection({ transport: 'ssh', @@ -71,10 +71,9 @@ conn.run((error, xmlOutput) => { if (error) { throw error; } - parseString(xmlOutput, (parseError, result) => { - if (parseError) { - throw parseError; - } - console.log(JSON.stringify(result)); - }); + + const Parser = new XMLParser(); + const result = Parser.parse(result); + + console.log(JSON.stringify(result)); }); diff --git a/docs/examples/rtvjoba.js b/docs/examples/rtvjoba.js index 26240db9..7b4bc9cd 100644 --- a/docs/examples/rtvjoba.js +++ b/docs/examples/rtvjoba.js @@ -1,5 +1,5 @@ const { Connection, CommandCall } = require('itoolkit'); -const { parseString } = require('xml2js'); +const { XMLParser } = require('fast-xml-parser'); const connection = new Connection({ @@ -15,10 +15,9 @@ connection.run((error, xmlOutput) => { if (error) { throw error; } - parseString(xmlOutput, (parseError, result) => { - if (parseError) { - throw parseError; - } - console.log(JSON.stringify(result)); - }); + + const Parser = new XMLParser(); + const result = Parser.parse(xmlOutput); + + console.log(JSON.stringify(result)); }); From 99bcf959561af5f90b6463e3a3c394ffd6ce6947 Mon Sep 17 00:00:00 2001 From: xWyatt Date: Fri, 15 Jul 2022 15:05:37 -0500 Subject: [PATCH 4/4] docs: Suggest 'fast-xml-parser' in `xmlToJson` deprecation message Signed-off-by: Wyatt Teeter Signed-off-by: xWyatt --- lib/Deprecated.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Deprecated.js b/lib/Deprecated.js index 85c30838..c4bb2e47 100644 --- a/lib/Deprecated.js +++ b/lib/Deprecated.js @@ -4347,7 +4347,7 @@ function iSh(sh, options) { * @returns {object[]} - The array of result objects. */ function xmlToJson(xml) { - xmlToJsonDeprecate('As of v1.0, \'xmlToJson\' is deprecated. Use xml2js npm package instead.'); + xmlToJsonDeprecate('As of v1.0, \'xmlToJson\' is deprecated. Use the fast-xml-parser npm package instead.'); const cmdRegG = /[\s\S]+?<\/cmd>/g; const shRegG = /[\s\S]+?<\/sh>/g;