1 | import { Element, ElementCompact } from './index'
|
2 | import * as convert from './index'
|
3 |
|
4 |
|
5 | const declarationCompact1: ElementCompact = { _declaration: { _attributes: { version: 2 } }};
|
6 | const declarationCompact2: ElementCompact = { _declaration: { _attributes: { version: '1.0', encoding: 'utf-8' }}};
|
7 | const declaration1: Element = { declaration: { }};
|
8 | const declaration2: Element = { declaration: { attributes: { version: '1.0', encoding: 'utf-8' }}};
|
9 |
|
10 |
|
11 | const instructionCompact: ElementCompact = { _instruction: { go: 'there' }};
|
12 | const instruction: Element = { elements:[{ type: 'instruction', name: 'go', instruction: 'there' }]};
|
13 |
|
14 |
|
15 | const commentCompact: ElementCompact = { _comment : 'Hello, World!' };
|
16 | const comment: Element = { elements: [{ type: 'comment', comment: 'Hello, World!' }]};
|
17 |
|
18 |
|
19 | const cdataCompact: ElementCompact = { _cdata: '<foo></bar>' };
|
20 | const cdata: Element = { elements : [{ type: 'cdata', cdata: '<foo></bar>' }]};
|
21 |
|
22 |
|
23 | const elementCompact1: ElementCompact = { a: {} };
|
24 | const element1: Element = { elements:[{ type: 'element', name: 'a' }]};
|
25 |
|
26 | const elementCompact2: ElementCompact = { a: { _attributes: { x: '1.234', y:'It\'s' }}};
|
27 | const element2: Element = { elements: [{ type: 'element', name: 'a', attributes: { x: '1.234', y: 'It\'s' }}]};
|
28 |
|
29 | const elementCompact3: ElementCompact = { a: { _text: ' Hi ' }};
|
30 | const element3: Element = { elements:[{ type: 'element', name: 'a', elements: [{ type: 'text', text: ' Hi ' }]}]};
|
31 |
|
32 | const elementCompact4: ElementCompact = { a: {}, b: {} };
|
33 | const element4: Element = { elements:[{ type: 'element', name: 'a' }, { type: 'element', name: 'b' }]};
|
34 |
|
35 | const elementCompact5: ElementCompact = { a: { b: {} }};
|
36 | const element5: Element = { elements: [{ type: 'element', name: 'a', elements: [{ type: 'element', name: 'b' }]}]};
|
37 |
|
38 | const xml = `
|
39 | <?xml version="1.0" encoding="utf-8"?>
|
40 | <note importance="high" logged="true">
|
41 | <title>Happy</title>
|
42 | <todo>Work</todo>
|
43 | <todo>Play</todo>
|
44 | </note>`;
|
45 |
|
46 |
|
47 | let jsResult1: any = convert.xml2js(xml, {compact:true});
|
48 | let jsResult2: any = convert.xml2js(xml, {compact:false});
|
49 |
|
50 |
|
51 | let jsonResult1: string = convert.xml2json(xml, {compact:true, spaces:4});
|
52 | let jsonResult2: string = convert.xml2json(xml, {compact:false});
|
53 |
|
54 |
|
55 | let xmlResult1: string = convert.js2xml({a:{}}, { compact:true, spaces:4});
|
56 | let xmlResult2: string = convert.js2xml({elements:[{type:'element', name:'a'}]}, {compact:false});
|
57 |
|
58 |
|
59 | let xmlResult3: string = convert.json2xml('{"a":{}}', { compact:true, spaces:4});
|
60 | let xmlResult4: string = convert.json2xml('{"elements":[{"type":"element","name":"a"}]}', {compact:false});
|