Skip to content

Commit 6fbb0a7

Browse files
authored
docs: Reference alternate XML parser (#345)
Signed-off-by: Wyatt Teeter <teeterwyatt@gmail.com> Signed-off-by: xWyatt <wteeter@ppi-global.com>
1 parent 6567f2e commit 6fbb0a7

File tree

6 files changed

+34
-38
lines changed

6 files changed

+34
-38
lines changed

README.md

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,11 @@ XMLSERVICE will run the command and respond with XML output.
4747
</myscript>
4848
```
4949

50-
`itoolkit` can run the same CL command with:
50+
`itoolkit`, with the help of an XML parser, can run the same CL command with:
5151

5252
```js
5353
const { Connection, CommandCall } = require('itoolkit');
54-
const { parseString } = require('xml2js');
54+
const { XMLParser } = require('fast-xml-parser');
5555

5656
const connection = new Connection({
5757
transport: 'ssh',
@@ -66,12 +66,11 @@ connection.run((error, xmlOutput) => {
6666
if (error) {
6767
throw error;
6868
}
69-
parseString(xmlOutput, (parseError, result) => {
70-
if (parseError) {
71-
throw parseError;
72-
}
73-
console.log(JSON.stringify(result));
74-
});
69+
70+
const Parser = new XMLParser();
71+
const result = Parser.parse(xmlOutput);
72+
73+
console.log(JSON.stringify(result));
7574
});
7675
```
7776

docs/examples/cosine.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const { Connection, ProgramCall } = require('itoolkit');
2-
const { parseString } = require('xml2js');
2+
const { XMLParser } = require('fast-xml-parser');
33

44
const conn = new Connection({
55
transport: 'ssh',
@@ -18,10 +18,9 @@ conn.run((error, xmlOutput) => {
1818
if (error) {
1919
throw error;
2020
}
21-
parseString(xmlOutput, (parseError, result) => {
22-
if (parseError) {
23-
throw parseError;
24-
}
25-
console.log(result.myscript.pgm[0].return[0].data[0]._); // 1
26-
});
21+
22+
const Parser = new XMLParser();
23+
const result = Parser.parse(xmlOutput);
24+
25+
console.log(result.myscript.pgm.return.data); // 1
2726
});

docs/examples/qusrobjd.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const { Connection, ProgramCall } = require('itoolkit');
2-
const { parseString } = require('xml2js');
2+
const { XMLParser } = require('fast-xml-parser');
33

44
const conn = new Connection({
55
transport: 'ssh',
@@ -71,10 +71,9 @@ conn.run((error, xmlOutput) => {
7171
if (error) {
7272
throw error;
7373
}
74-
parseString(xmlOutput, (parseError, result) => {
75-
if (parseError) {
76-
throw parseError;
77-
}
78-
console.log(JSON.stringify(result));
79-
});
74+
75+
const Parser = new XMLParser();
76+
const result = Parser.parse(result);
77+
78+
console.log(JSON.stringify(result));
8079
});

docs/examples/rtvjoba.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const { Connection, CommandCall } = require('itoolkit');
2-
const { parseString } = require('xml2js');
2+
const { XMLParser } = require('fast-xml-parser');
33

44

55
const connection = new Connection({
@@ -15,10 +15,9 @@ connection.run((error, xmlOutput) => {
1515
if (error) {
1616
throw error;
1717
}
18-
parseString(xmlOutput, (parseError, result) => {
19-
if (parseError) {
20-
throw parseError;
21-
}
22-
console.log(JSON.stringify(result));
23-
});
18+
19+
const Parser = new XMLParser();
20+
const result = Parser.parse(xmlOutput);
21+
22+
console.log(JSON.stringify(result));
2423
});

docs/migratation-guide-v1.0.rst

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@ Sync Mode Operations
2020
``iConn.run()`` no longer supports sync mode. Sync mode is not reccommended and since it did not work properly it was removed.
2121
See (`#32 <https://github.com/IBM/nodejs-itoolkit/issues/32>`__) for more details.
2222

23-
``iConn.setTimeout()`` is removed. This function was used to set the timeout for ``iConn.run``
23+
``iConn.setTimeout()`` is removed. This function was used to set the timeout for ``iConn.run``
2424
sync mode.
2525

2626
iSql Authentication
2727
-------------------
2828

29-
``iSql.connect()`` and ``iSql.setOptions()`` are removed. These functions were used in conjunction
29+
``iSql.connect()`` and ``iSql.setOptions()`` are removed. These functions were used in conjunction
3030
for XMLSERVICE user
3131
authentication. The transports already handle user authentication.
3232

@@ -81,8 +81,8 @@ Migrating from ``iConn`` to ``Connection``
8181
passed to their run methods. You cannot simply replace iConn with Connection without adjusting
8282
your callbacks. See the :ref:`iconn-to-connection-run` section.
8383

84-
When connecting using idb-connector, ``iConn`` takes 3 arguments: ``database``, ``username``,
85-
and ``password``. These can be passed as attributes on the ``transportOptions`` attribute of the
84+
When connecting using idb-connector, ``iConn`` takes 3 arguments: ``database``, ``username``,
85+
and ``password``. These can be passed as attributes on the ``transportOptions`` attribute of the
8686
object passed to ``Connection`` and specify the transport is ``idb``. eg.
8787

8888
.. code:: js
@@ -95,9 +95,9 @@ object passed to ``Connection`` and specify the transport is ``idb``. eg.
9595
});
9696
9797
When connecting using rest, ``iConn`` takes 4 arguments: ``database``, ``username``, ``password``,
98-
and ``options``. The options object included ``host``, ``port``, and ``path`` to
99-
generate the url string. Instead specify ``database``, ``username``, ``password``, and ``url``
100-
on the ``transportOptions`` attribute of the object passed to ``Connection`` and specify the
98+
and ``options``. The options object included ``host``, ``port``, and ``path`` to
99+
generate the url string. Instead specify ``database``, ``username``, ``password``, and ``url``
100+
on the ``transportOptions`` attribute of the object passed to ``Connection`` and specify the
101101
transport is ``rest``. eg.
102102

103103
.. code:: js
@@ -292,7 +292,7 @@ xmlToJson
292292
---------
293293

294294
``xmlToJson`` is deprecated and will be removed in ``v2.x``. Use
295-
`xml2js <https://www.npmjs.com/package/xml2js>`__ instead.
295+
an external XML parser such as `fast-xml-parser <https://www.npmjs.com/package/fast-xml-parser>`__.
296296

297297
iDataQueue
298298
----------

lib/Deprecated.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4345,7 +4345,7 @@ function iSh(sh, options) {
43454345
* @returns {object[]} - The array of result objects.
43464346
*/
43474347
function xmlToJson(xml) {
4348-
xmlToJsonDeprecate('As of v1.0, \'xmlToJson\' is deprecated. Use xml2js npm package instead.');
4348+
xmlToJsonDeprecate('As of v1.0, \'xmlToJson\' is deprecated. Use the fast-xml-parser npm package instead.');
43494349

43504350
const cmdRegG = /<cmd.*?>[\s\S]+?<\/cmd>/g;
43514351
const shRegG = /<sh.*?>[\s\S]+?<\/sh>/g;

0 commit comments

Comments
 (0)