# diff-js-xml

> XML JSON object compare module

Latest version **1.0.8** (published 2023-04-28) · MIT license · 0 weekly downloads

## Install

```sh
npm install diff-js-xml
pnpm add diff-js-xml
yarn add diff-js-xml
bun add diff-js-xml
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.8 |
| Published | 2023-04-28 |
| First published | 2018-12-09 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 12.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 12 |
| Author | Joost van Dieten |
| Maintainers | test-assured |
| Keywords | xml compare, json compare, xmldiff, json diff, xml2xml diff, json2json diff |

## Links

- npm: https://www.npmjs.com/package/diff-js-xml
- Repository: https://github.com/jvdieten/diff-js-xml
- Homepage: https://github.com/jvdieten/diff-js-xml#readme
- Issues: https://github.com/jvdieten/diff-js-xml/issues
- npm.io page: https://npm.io/package/diff-js-xml

## Dependencies (2)

- [xml-js](https://npm.io/package/xml-js.md) ^1.6.11
- [underscore](https://npm.io/package/underscore.md) ^1.10.2

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 1.0.8 (latest) — 2023-04-28
- 1.0.7 — 2023-04-28
- 1.0.6 — 2020-07-20
- 1.0.5 — 2019-07-25
- 1.0.4 — 2018-12-18
- 1.0.3 — 2018-12-17
- 1.0.2 — 2018-12-17
- 1.0.1 — 2018-12-10
- 1.0.0 — 2018-12-10
- 0.0.6 — 2018-12-10
- 0.0.5 — 2018-12-09
- 0.0.4 — 2018-12-09
- 0.0.3 — 2018-12-09

## README

[![Travis-ci Build Status](https://travis-ci.com/jvdieten/diff-js-xml.svg?branch=master)](https://travis-ci.com/jvdieten/diff-js-xml)
[![NPM](https://nodei.co/npm/diff-js-xml.png)](https://nodei.co/npm/diff-js-xml/)

# diff-js-xml
Module to compare XML or JSON objects very useful for A-B testing main features:

- Compare elements and element values
- Compare with wildcards for element values
- Clear reporting of differences in result array see below

## Installation
```
$ npm install diff-js-xml --save
```
### Usage for comparing XML
```javascript
const tool = require('diff-js-xml');
 
tool.diffAsXml(lhsXML, rhsXML, schema, options, (result) => {

});
```
Before comparing xml is first transformed into JSON object with **xml-js** module  

**lhsXML and rhsXML** are the two XML strings to compare.

**schema**  options for specific keys for example skip one of them or null if not needed

```javascript
const schema = { elementA: { skipKey:true}}
```

**options** generic options or null if not needed current options available:
- **compareElementValues** to disable comparing of element values default is true
- **xml2jsOptions** pass through options to xml-js. xml-js has its own default options, and we override a handful: 
`compact: true, ignoreDoctype: true, ignoreDeclaration: true, ignoreAttributes: true`
You can override these, or others, but most option combinations have not been tested carefully so use caution.

```javascript
const options = {compareElementValues: false}
```

**result** array returned from the diff method containing all the differences with following result types:

**missing element** xml element is not found in leftXML or rightXML

**difference in element value** values of elements is not equal 

**Example of result**
```
[ { path: 'element.subelement',
    type: 'difference in field value',
    message: 'field element.subelement has lhs value TestA and rhs value TestB' } ]
```

#### wildcard values

For A-B testing purposes it can be very handy to compare with wildcards if for exammple you are not interested in all 
the data. You can put an * in the first (lhs) xml file. The result of this compare will be no differences.

```javascript
const lhsxml =
    '<string-array name="languages_array"><item>*</item><item2>Chinese</item2><item3>French</item3><item4>Spanish</item4></string-array>'
const string =
    '<string-array name="languages_array"><item>Dutch</item><item2>Chinese</item2><item3>French</item3><item4>Spanish</item4></string-array>'
```

### Usage for comparing JSON
```javascript
const tool = require('diff-js-xml');
 
tool.diff(lhsObject, rhsObject, schema, options, (result) => {

});
```
**lhsObject and rhsObject** are the two JSON objects to compare.
**result** is an array returned from the diff method containing all the differences see above.


## Contributors
* Joost van Dieten <joost.van.dieten@testassured.nl> (http://www.testassured.nl)

---
_Source: https://npm.io/package/diff-js-xml · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
