0.1.5 • Published 2 years ago
simple-xml-merge v0.1.5
Simple XML merge
Installation
#Installation
npm install simple-xml-merge
Usage
Basic example
import { mergeXml } from 'simple-xml-merge';
const xmlData1: string = ''; //read xml from fs/network/Buffer
const xmlData2: string = ''; //read xml from fs/network/Buffer
const mergedXml = mergeXml(xmlData1, xmlData2);
//Serialize and use
console.log(mergedXml.toString());
Example with node "name" comparator
import { mergeXml } from 'simple-xml-merge';
const xmlData1: string = ''; //read xml from fs/network/Buffer
const xmlData2: string = ''; //read xml from fs/network/Buffer
const mergedXml = mergeXml(xmlData1, xmlData2, (node1, node2) => node1.name === node2.name);
//Serialize and use
console.log(mergedXml.toString());
With comparator it's possible to define rules for nodes merge. For example, XMLs
<root>
<test attr="value">
</root>
and
<root>
<test attr="value2">
</root>
will be merged to:
<root>
<test attr="value2">
</root>
Without comparator the full comparison (name, attributes) will be used and such merge result to:
<root>
<test attr="value">
<test attr="value2">
</root>