forked from Leonidas-from-XIV/node-xml2js
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathxml2js-tests.ts
More file actions
91 lines (78 loc) · 2.28 KB
/
xml2js-tests.ts
File metadata and controls
91 lines (78 loc) · 2.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/// <reference types="node"/>
import xml2js = require('nativescript-xml2js');
import * as processors from 'nativescript-xml2js/lib/processors';
xml2js.parseString('<root>Hello xml2js!</root>', (err: any, result: any) => { });
xml2js.parseString('<root>Hello xml2js!</root>', {trim: true}, (err: any, result: any) => { });
xml2js.parseString('<root>Hello xml2js!</root>', {
attrkey: '$',
charkey: '_',
explicitCharkey: false,
trim: false,
normalizeTags: false,
explicitRoot: true,
emptyTag: '',
explicitArray: true,
ignoreAttrs: false,
mergeAttrs: false,
validator: undefined,
xmlns: false,
explicitChildren: false,
childkey: '$$',
preserveChildrenOrder: false,
charsAsChildren: false,
includeWhiteChars: false,
async: false,
strict: true,
attrNameProcessors: undefined,
attrValueProcessors: undefined,
tagNameProcessors: undefined,
valueProcessors: undefined
}, (err: any, result: any) => { });
xml2js.parseString('<root>Hello xml2js!</root>', {
attrNameProcessors: [processors.firstCharLowerCase],
attrValueProcessors: [processors.normalize],
tagNameProcessors: [processors.stripPrefix],
valueProcessors: <any>[processors.parseBooleans, processors.parseNumbers]
}, (err: any, result: any) => { });
var builder = new xml2js.Builder({
renderOpts: {
pretty: false
}
});
var builder = new xml2js.Builder({
rootName: 'root',
renderOpts: {
pretty: true,
indent: ' ',
newline: '\n'
},
xmldec: {
version: '1.0',
encoding: 'UTF-8',
standalone: true
},
doctype: { ext: 'hello.dtd' },
headless: false,
cdata: false
});
var outString = builder.buildObject({
'hello': 'xml2js!'
});
var parser = new xml2js.Parser();
parser.on('end', (result: any) => {
console.log("Parser Finished");
return;
});
var v1Defaults = xml2js.defaults['0.1'];
v1Defaults.async = true;
var v2Defaults = xml2js.defaults['0.2'];
v2Defaults.async = false;
v2Defaults.chunkSize = 20000;
import fs = require('fs');
fs.readFile(__dirname + '/foo.xml', function(err, data) {
parser.parseString(data, function (err: any, result: any) {
console.dir(result);
console.log('Done');
});
});