-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathxml-build.js
More file actions
32 lines (29 loc) · 803 Bytes
/
xml-build.js
File metadata and controls
32 lines (29 loc) · 803 Bytes
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
import { XMLBuilder } from 'fast-xml-parser';
const books = [
{
author: 'Gambardella, Matthew',
title: "XML Developer's Guide",
genre: 'Computer',
price: 44.95,
publish_date: '2000-10-01',
description: 'An in-depth look at creating applications with XML.'
},
{
author: 'Ralls, Kim',
title: 'Midnight Rain',
genre: 'Fantasy',
price: 5.95,
publish_date: '2000-12-16',
description: 'A former architect battles corporate zombies, \n' +
' an evil sorceress, and her own childhood to become queen \n' +
' of the world.'
}
];
const builder = new XMLBuilder({
arrayNodeName: "book"
});
const xmlContent = `<?xml version="1.0"?>
<catalog>
${builder.build(books)}
</catalog>`
console.log(`xml: `, xmlContent.substring(0, 118));