# validate-ddex

## About

Validates DDEX to RDR-N 1.4 standard, using the [validate-with-xmllint package](https://www.npmjs.com/package/validate-with-xmllint), which is a wrapper for `xmllint`.

### XSD Schema

DDEX publishes two XML Schema Definition (XSD) files for each standard - one for the structure of the 'message XSD' and one for the allowed-values, the 'AVS XSD'. These are stored in the 'schema' folder. There is also a `xmldsig-core-schema.xsd` file, which is imported into the message schema.

Useful links:

- [Guidance on DDEX XSD files](https://kb.ddex.net/general-implementation-guidance/validating-ddex-messages/xml-validation/).

- [Link to RDR-N 1.4 standard](https://kb.ddex.net/reference-material/past-versions-of-standards/).


## Installation

```bash
yarn install
```

## Usage

- Run `mkdir generated input`
- Add XML files to be validated to the `input` folder.
- Run `yarn validate-ddex`
- DDEX validation errors will be written to the `generated` folder (note - formatting of these errors could be improved)

Please note this script can take some time for very large XML files (100,000s of rows).

## Notes

### Use with other schemas

This module validates XML against the RDR-N 1.4 standard. This could be adapted for use with another standard by replacing the files in the `schema` directory. The `validate-with-xmlint` package cannot currently validate against online schemas, so all XSD schemas must be downloaded to the schema folder.

Where an online XSD file is imported into another DDEX document, this import must be changed instead to the local file.

For example, the RDR-N 1.4 music-licensing-companies.xsd file has the following import:

```
<xs:import namespace="http://www.w3.org/2000/09/xmldsig#" schemaLocation="http://www.w3.org/TR/2002/REC-xmldsig-core-20020212/xmldsig-core-schema.xsd"/>
```

The schema at http://www.w3.org/TR/2002/REC-xmldsig-core-20020212/xmldsig-core-schema.xsd must  be downloaded, and this import changed to:

```
<xs:import namespace="http://www.w3.org/2000/09/xmldsig#" schemaLocation="xmldsig-core-schema.xsd"/>
```
