xml-toolkit 0.0.9 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +54 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,4 +1,57 @@
|
|
|
1
1
|
# node-xml-toolkit
|
|
2
2
|
Collection of classes for dealing with XML
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
# Installation
|
|
5
|
+
|
|
6
|
+
```
|
|
7
|
+
npm i xml-toolkit
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
# Using
|
|
11
|
+
* [Reading a Record List](https://github.com/do-/node-xml-toolkit/wiki/Use-Case:-Reading-a-Record-List)
|
|
12
|
+
|
|
13
|
+
```js
|
|
14
|
+
const {XMLReader, XMLNode} = require ('xml-toolkit')
|
|
15
|
+
|
|
16
|
+
const records = new XMLReader ({
|
|
17
|
+
filterElements : 'Record',
|
|
18
|
+
map : XMLNode.toObject ({})
|
|
19
|
+
}).process (xmlSource)
|
|
20
|
+
|
|
21
|
+
// ...then:
|
|
22
|
+
// await someLoader.load (records)
|
|
23
|
+
|
|
24
|
+
// ...or
|
|
25
|
+
// for await (const record of records) { // pull parser mode
|
|
26
|
+
|
|
27
|
+
// ...or
|
|
28
|
+
// records.on ('error', e => console.log (e))
|
|
29
|
+
// records.pipe (nextStream)
|
|
30
|
+
|
|
31
|
+
// ...or
|
|
32
|
+
// records.on ('error', e => console.log (e))
|
|
33
|
+
// records.on ('data', record => doSomethingWith (record))
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
* [Getting a Single Element](https://github.com/do-/node-xml-toolkit/wiki/Use-Case:-Getting-a-Single-Element)
|
|
37
|
+
|
|
38
|
+
```js
|
|
39
|
+
const {XMLReader, XMLNode} = require ('xml-toolkit')
|
|
40
|
+
|
|
41
|
+
const data = await new XMLReader ({
|
|
42
|
+
filterElements : 'MyElementName',
|
|
43
|
+
map : XMLNode.toObject ({})
|
|
44
|
+
}).process (xmlSource).findFirst ()
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
* [Patching XML](https://github.com/do-/node-xml-toolkit/wiki/Use-Case:-Patching-XML)
|
|
48
|
+
|
|
49
|
+
```js
|
|
50
|
+
const {XMLReader} = require ('xml-toolkit')
|
|
51
|
+
|
|
52
|
+
let xmlResult = ''; for await (const node of new XMLReader ().process (xmlSource)) xmlResult +=
|
|
53
|
+
node.isCharacters && node.parent.localName === 'ThePlaceHolder' ? id :
|
|
54
|
+
node.xml
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
More information available in [wiki docs](https://github.com/do-/node-xml-toolkit/wiki).
|