cda-schematron-validator 1.0.4 → 1.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,70 @@
1
+ # For most projects, this workflow file will not need changing; you simply need
2
+ # to commit it to your repository.
3
+ #
4
+ # You may wish to alter this file to override the set of languages analyzed,
5
+ # or to provide custom queries or build logic.
6
+ #
7
+ # ******** NOTE ********
8
+ # We have attempted to detect the languages in your repository. Please check
9
+ # the `language` matrix defined below to confirm you have the correct set of
10
+ # supported CodeQL languages.
11
+ #
12
+ name: "CodeQL"
13
+
14
+ on:
15
+ push:
16
+ branches: [ main ]
17
+ pull_request:
18
+ # The branches below must be a subset of the branches above
19
+ branches: [ main ]
20
+ schedule:
21
+ - cron: '34 18 * * 4'
22
+
23
+ jobs:
24
+ analyze:
25
+ name: Analyze
26
+ runs-on: ubuntu-latest
27
+ permissions:
28
+ actions: read
29
+ contents: read
30
+ security-events: write
31
+
32
+ strategy:
33
+ fail-fast: false
34
+ matrix:
35
+ language: [ 'javascript' ]
36
+ # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
37
+ # Learn more about CodeQL language support at https://git.io/codeql-language-support
38
+
39
+ steps:
40
+ - name: Checkout repository
41
+ uses: actions/checkout@v3
42
+
43
+ # Initializes the CodeQL tools for scanning.
44
+ - name: Initialize CodeQL
45
+ uses: github/codeql-action/init@v2
46
+ with:
47
+ languages: ${{ matrix.language }}
48
+ # If you wish to specify custom queries, you can do so here or in a config file.
49
+ # By default, queries listed here will override any specified in a config file.
50
+ # Prefix the list here with "+" to use these queries and those in the config file.
51
+ # queries: ./path/to/local/query, your-org/your-repo/queries@main
52
+
53
+ # Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
54
+ # If this step fails, then you should remove it and run the build manually (see below)
55
+ - name: Autobuild
56
+ uses: github/codeql-action/autobuild@v2
57
+
58
+ # ℹ️ Command-line programs to run using the OS shell.
59
+ # 📚 https://git.io/JvXDl
60
+
61
+ # ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
62
+ # and modify them (or add more) to build your code if your project
63
+ # uses a compiled language
64
+
65
+ #- run: |
66
+ # make bootstrap
67
+ # make release
68
+
69
+ - name: Perform CodeQL Analysis
70
+ uses: github/codeql-action/analyze@v2
package/.jshintrc CHANGED
@@ -1,96 +1,96 @@
1
- /*jshint :esversion 6 */
2
- {
3
- // JSHint Default Configuration File (as on JSHint website)
4
- // See http://jshint.com/docs/ for more details
5
-
6
- "maxerr": 500, // {int} Maximum error before stopping
7
-
8
- // Enforcing
9
- "bitwise": true, // true: Prohibit bitwise operators (&, |, ^, etc.)
10
- "camelcase": false, // true: Identifiers must be in camelCase
11
- "curly": false, // true: Require {} for every new block or scope
12
- "eqeqeq": true, // true: Require triple equals (===) for comparison
13
- "forin": true, // true: Require filtering for..in loops with obj.hasOwnProperty()
14
- "immed": true, // true: Require immediate invocations to be wrapped in parens e.g. `(function () { } ());`
15
- "indent": false, // {int} Number of spaces to use for indentation
16
- "latedef": false, // true: Require variables/functions to be defined before being used
17
- "newcap": false, // true: Require capitalization of all constructor functions e.g. `new F()`
18
- "noarg": true, // true: Prohibit use of `arguments.caller` and `arguments.callee`
19
- "noempty": true, // true: Prohibit use of empty blocks
20
- "nonew": false, // true: Prohibit use of constructors for side-effects (without assignment)
21
- "plusplus": false, // true: Prohibit use of `++` & `--`
22
- "quotmark": "single", // Quotation mark consistency:
23
- // false : do nothing (default)
24
- // true : ensure whatever is used is consistent
25
- // "single" : require single quotes
26
- // "double" : require double quotes
27
- "undef": true, // true: Require all non-global variables to be declared (prevents global leaks)
28
- "unused": true, // true: Require all defined variables be used
29
- "strict": false, // true: Requires all functions run in ES5 Strict Mode
30
- "trailing": false, // true: Prohibit trailing whitespaces
31
- "maxparams": false, // {int} Max number of formal params allowed per function
32
- "maxdepth": false, // {int} Max depth of nested blocks (within functions)
33
- "maxstatements": false, // {int} Max number statements per function
34
- "maxcomplexity": false, // {int} Max cyclomatic complexity per function
35
- "maxlen": false, // {int} Max number of characters per line
36
-
37
- // Relaxing
38
- "asi": false, // true: Tolerate Automatic Semicolon Insertion (no semicolons)
39
- "boss": false, // true: Tolerate assignments where comparisons would be expected
40
- "debug": true, // true: Allow debugger statements e.g. browser breakpoints.
41
- "eqnull": false, // true: Tolerate use of `== null`
42
- "es5": false, // true: Allow ES5 syntax (ex: getters and setters)
43
- "esversion": 6,
44
- "esnext": false, // true: Allow ES.next (ES6) syntax (ex: `const`)
45
- "moz": false, // true: Allow Mozilla specific syntax (extends and overrides esnext features)
46
- // (ex: `for each`, multiple try/catch, function expression...)
47
- "evil": false, // true: Tolerate use of `eval` and `new Function()`
48
- "expr": true, // true: Tolerate `ExpressionStatement` as Programs
49
- "funcscope": false, // true: Tolerate defining variables inside control statements"
50
- "globalstrict": false, // true: Allow global "use strict" (also enables 'strict')
51
- "iterator": false, // true: Tolerate using the `__iterator__` property
52
- "lastsemic": false, // true: Tolerate omitting a semicolon for the last statement of a 1-line block
53
- "laxbreak": true, // true: Tolerate possibly unsafe line breakings
54
- "laxcomma": true, // true: Tolerate comma-first style coding
55
- "loopfunc": false, // true: Tolerate functions being defined in loops
56
- "multistr": false, // true: Tolerate multi-line strings
57
- "proto": false, // true: Tolerate using the `__proto__` property
58
- "scripturl": false, // true: Tolerate script-targeted URLs
59
- "smarttabs": true, // true: Tolerate mixed tabs/spaces when used for alignment
60
- "shadow": false, // true: Allows re-define variables later in code e.g. `var x=1; x=2;`
61
- "sub": false, // true: Tolerate using `[]` notation when it can still be expressed in dot notation
62
- "supernew": false, // true: Tolerate `new function () { ... };` and `new Object;`
63
- "validthis": false, // true: Tolerate using this in a non-constructor function
64
-
65
- // Environments
66
- "browser": true, // Web Browser (window, document, etc)
67
- "couch": false, // CouchDB
68
- "devel": true, // Development/debugging (alert, confirm, etc)
69
- "dojo": false, // Dojo Toolkit
70
- "jquery": true, // jQuery
71
- "mootools": false, // MooTools
72
- "node": false, // Node.js
73
- "nonstandard": false, // Widely adopted globals (escape, unescape, etc)
74
- "prototypejs": false, // Prototype and Scriptaculous
75
- "rhino": false, // Rhino
76
- "worker": false, // Web Workers
77
- "wsh": false, // Windows Scripting Host
78
- "yui": false, // Yahoo User Interface
79
-
80
- // Legacy
81
- "nomen": false, // true: Prohibit dangling `_` in variables
82
- "onevar": false, // true: Allow only one `var` statement per function
83
- "passfail": false, // true: Stop on first error
84
- "white": false, // true: Check against strict whitespace and indentation rules
85
-
86
- // Custom Globals
87
- "globals": {
88
- "describe": false,
89
- "it": false,
90
- "before": false,
91
- "beforeEach": false,
92
- "after": false,
93
- "afterEach": false,
94
- "module" : false
95
- }
96
- }
1
+ /*jshint :esversion 6 */
2
+ {
3
+ // JSHint Default Configuration File (as on JSHint website)
4
+ // See http://jshint.com/docs/ for more details
5
+
6
+ "maxerr": 500, // {int} Maximum error before stopping
7
+
8
+ // Enforcing
9
+ "bitwise": true, // true: Prohibit bitwise operators (&, |, ^, etc.)
10
+ "camelcase": false, // true: Identifiers must be in camelCase
11
+ "curly": false, // true: Require {} for every new block or scope
12
+ "eqeqeq": true, // true: Require triple equals (===) for comparison
13
+ "forin": true, // true: Require filtering for..in loops with obj.hasOwnProperty()
14
+ "immed": true, // true: Require immediate invocations to be wrapped in parens e.g. `(function () { } ());`
15
+ "indent": false, // {int} Number of spaces to use for indentation
16
+ "latedef": false, // true: Require variables/functions to be defined before being used
17
+ "newcap": false, // true: Require capitalization of all constructor functions e.g. `new F()`
18
+ "noarg": true, // true: Prohibit use of `arguments.caller` and `arguments.callee`
19
+ "noempty": true, // true: Prohibit use of empty blocks
20
+ "nonew": false, // true: Prohibit use of constructors for side-effects (without assignment)
21
+ "plusplus": false, // true: Prohibit use of `++` & `--`
22
+ "quotmark": "single", // Quotation mark consistency:
23
+ // false : do nothing (default)
24
+ // true : ensure whatever is used is consistent
25
+ // "single" : require single quotes
26
+ // "double" : require double quotes
27
+ "undef": true, // true: Require all non-global variables to be declared (prevents global leaks)
28
+ "unused": true, // true: Require all defined variables be used
29
+ "strict": false, // true: Requires all functions run in ES5 Strict Mode
30
+ "trailing": false, // true: Prohibit trailing whitespaces
31
+ "maxparams": false, // {int} Max number of formal params allowed per function
32
+ "maxdepth": false, // {int} Max depth of nested blocks (within functions)
33
+ "maxstatements": false, // {int} Max number statements per function
34
+ "maxcomplexity": false, // {int} Max cyclomatic complexity per function
35
+ "maxlen": false, // {int} Max number of characters per line
36
+
37
+ // Relaxing
38
+ "asi": false, // true: Tolerate Automatic Semicolon Insertion (no semicolons)
39
+ "boss": false, // true: Tolerate assignments where comparisons would be expected
40
+ "debug": true, // true: Allow debugger statements e.g. browser breakpoints.
41
+ "eqnull": false, // true: Tolerate use of `== null`
42
+ "es5": false, // true: Allow ES5 syntax (ex: getters and setters)
43
+ "esversion": 6,
44
+ "esnext": false, // true: Allow ES.next (ES6) syntax (ex: `const`)
45
+ "moz": false, // true: Allow Mozilla specific syntax (extends and overrides esnext features)
46
+ // (ex: `for each`, multiple try/catch, function expression...)
47
+ "evil": false, // true: Tolerate use of `eval` and `new Function()`
48
+ "expr": true, // true: Tolerate `ExpressionStatement` as Programs
49
+ "funcscope": false, // true: Tolerate defining variables inside control statements"
50
+ "globalstrict": false, // true: Allow global "use strict" (also enables 'strict')
51
+ "iterator": false, // true: Tolerate using the `__iterator__` property
52
+ "lastsemic": false, // true: Tolerate omitting a semicolon for the last statement of a 1-line block
53
+ "laxbreak": true, // true: Tolerate possibly unsafe line breakings
54
+ "laxcomma": true, // true: Tolerate comma-first style coding
55
+ "loopfunc": false, // true: Tolerate functions being defined in loops
56
+ "multistr": false, // true: Tolerate multi-line strings
57
+ "proto": false, // true: Tolerate using the `__proto__` property
58
+ "scripturl": false, // true: Tolerate script-targeted URLs
59
+ "smarttabs": true, // true: Tolerate mixed tabs/spaces when used for alignment
60
+ "shadow": false, // true: Allows re-define variables later in code e.g. `var x=1; x=2;`
61
+ "sub": false, // true: Tolerate using `[]` notation when it can still be expressed in dot notation
62
+ "supernew": false, // true: Tolerate `new function () { ... };` and `new Object;`
63
+ "validthis": false, // true: Tolerate using this in a non-constructor function
64
+
65
+ // Environments
66
+ "browser": true, // Web Browser (window, document, etc)
67
+ "couch": false, // CouchDB
68
+ "devel": true, // Development/debugging (alert, confirm, etc)
69
+ "dojo": false, // Dojo Toolkit
70
+ "jquery": true, // jQuery
71
+ "mootools": false, // MooTools
72
+ "node": false, // Node.js
73
+ "nonstandard": false, // Widely adopted globals (escape, unescape, etc)
74
+ "prototypejs": false, // Prototype and Scriptaculous
75
+ "rhino": false, // Rhino
76
+ "worker": false, // Web Workers
77
+ "wsh": false, // Windows Scripting Host
78
+ "yui": false, // Yahoo User Interface
79
+
80
+ // Legacy
81
+ "nomen": false, // true: Prohibit dangling `_` in variables
82
+ "onevar": false, // true: Allow only one `var` statement per function
83
+ "passfail": false, // true: Stop on first error
84
+ "white": false, // true: Check against strict whitespace and indentation rules
85
+
86
+ // Custom Globals
87
+ "globals": {
88
+ "describe": false,
89
+ "it": false,
90
+ "before": false,
91
+ "beforeEach": false,
92
+ "after": false,
93
+ "afterEach": false,
94
+ "module" : false
95
+ }
96
+ }
@@ -1,18 +1,37 @@
1
- {
2
- "version": "0.2.0",
3
- "configurations": [
4
- {
5
- "name": "Mocha (Test single file)",
6
- "type": "node",
7
- "request": "launch",
8
- "runtimeArgs": [
9
- "${workspaceRoot}/node_modules/.bin/mocha",
10
- "--inspect-brk",
11
- "${relativeFile}",
12
- ],
13
- "console": "integratedTerminal",
14
- "internalConsoleOptions": "neverOpen",
15
- "port": 9229
16
- }
17
- ]
18
- }
1
+ {
2
+ "version": "0.2.0",
3
+ "configurations": [
4
+ {
5
+ "args": [
6
+ "--timeout",
7
+ "999999",
8
+ "--colors",
9
+ "${workspaceFolder}/test"
10
+ ],
11
+ "internalConsoleOptions": "openOnSessionStart",
12
+ "name": "Mocha Tests",
13
+ "program": "${workspaceFolder}/node_modules/mocha/bin/_mocha",
14
+ "request": "launch",
15
+ "skipFiles": [
16
+ "<node_internals>/**"
17
+ ],
18
+ "type": "pwa-node"
19
+ },
20
+ {
21
+ "args": [
22
+ "--timeout",
23
+ "999999",
24
+ "--colors",
25
+ "${relativeFile}"
26
+ ],
27
+ "internalConsoleOptions": "openOnSessionStart",
28
+ "name": "Mocha Test Current File",
29
+ "program": "${workspaceFolder}/node_modules/mocha/bin/_mocha",
30
+ "request": "launch",
31
+ "skipFiles": [
32
+ "<node_internals>/**"
33
+ ],
34
+ "type": "pwa-node"
35
+ }
36
+ ]
37
+ }
package/README.md CHANGED
@@ -1,132 +1,140 @@
1
- # cda-schematron-validator
2
- A fork to the original cda-schematron. All credit to Eric Wadkins. Visit the github https://github.com/ewadkins/cda-schematron for the original repo.
3
-
4
- This is just a cosmetic change with updated node modules, a couple of minor bugs observed, and esversion 6 changes.
5
-
6
- The changes are fully backward compatible. So, leaving the original documentation as is below.
7
-
8
- ### New option parameter parsedSchematronMap
9
- In addition to everything that was possible,
10
- you can now supply a new option parameter `parsedSchematronMap`. You can create a schematron map as follows.
11
-
12
- ```javascript
13
- const fs = require('fs');
14
- const dom = require('@xmldom/xmldom').DOMParser;
15
- const { parseSchematron, validate } = require('cda-schematron-validator');
16
- const schematronString = fs.readFileSync('SchematronFilePath', 'utf-8').toString();
17
- const schematronDoc = new dom().parseFromString(schematronString);
18
- const schematronMap = parseSchematron(schematronDoc);
19
- const options = {
20
- parsedSchematronMap: schematronMap
21
- };
22
- const results = validate('xml string or file path', 'schematron sting, file path or null', options);
23
- ```
24
- If a schematron map is provided, the schematron string or path will not be read.
25
-
26
- To install this npm module, it will be
27
-
28
- ```
29
- npm install cda-schematron-validator
30
- ```
31
- Mocha VS Code configuratin added to directly execute the test file in `test/tests.js` using VS Code.
32
-
33
-
34
- # Original Documentation of the cda-schematron
35
- # cda-schematron
36
-
37
- A javascript implementation of schematron testing for XML documents. This specifically resolves a need for a package that allows a quick, reliable install for validating HL7 clinical documents, such as C-CDA.
38
-
39
- Check out [cda-schematron-server](https://github.com/ewadkins/cda-schematron-server), a server wrapper of **cda-schematron**, for easy schematron validation.
40
-
41
- ### Validating xml
42
- ```javascript
43
- var validator = require('cda-schematron');
44
-
45
- var xmlPath = 'someFile.xml';
46
- var schematronPath = 'someFile.sch';
47
-
48
- var fs = require('fs');
49
- var xml = fs.readFileSync(xmlPath).toString();
50
- var schematron = fs.readFileSync(schematronPath).toString();
51
-
52
- var results = validator.validate(xml, schematron);
53
- ```
54
- File paths can also be passed to the validator directly. The following lines all return the same results:
55
- ```javascript
56
- var results = validator.validate(xml, schematronPath);
57
- ```
58
- ```javascript
59
- var results = validator.validate(xmlPath, schematron);
60
- ```
61
- ```javascript
62
- var results = validator.validate(xmlPath, schematronPath);
63
- ```
64
-
65
- ### Results
66
- ```results``` is an object containing arrays ```errors```, ```warnings```, and ```ignoreds```.
67
-
68
- **Errors** and **warnings** are reported as determined by the schematron and test descriptions. They are of the following form:
69
- ```javascript
70
- {
71
- type: type, // "error" or "warning"
72
- test: test, // xpath test
73
- simplifiedTest: simplifiedTest, // xpath test with resource values included, if applicable, null otherwise
74
- description: description, // schematron description of the test case
75
- line: line, // line number of the violating context
76
- path: path, // xpath path of the violating context
77
- patternId: patternId, // schematron-assigned pattern id
78
- ruleId: ruleId, // schematron-assigned rule id
79
- assertionId: assertionId, // schematron-assigned assertion id
80
- context: context, // xpath context of the rule
81
- xml: xml // xml snippet of the violating context
82
- }
83
- ```
84
-
85
- **Ignored** tests are those that resulted in an exception while running (eg. the test is invalid xpath and could not be parsed properly) and require manual inspection. They are of the following form:
86
- ```javascript
87
- {
88
- errorMessage: errorMessage, // reason for the exception/ignoring the test
89
- type: type, // "error" or "warning"
90
- test: test, // xpath test
91
- simplifiedTest: simplifiedTest, // xpath test with resource values included, if applicable, null otherwise
92
- description: description, // schematron description of the test case
93
- patternId: patternId, // schematron-assigned pattern id
94
- ruleId: ruleId, // schematron-assigned rule id
95
- assertionId: assertionId, // schematron-assigned assertion id
96
- context: context, // xpath context of the rule
97
- }
98
- ```
99
-
100
- ### Options
101
- The ```validate``` function takes in an ```options``` object as an optional third argument. The three fields that can be included in ```options``` are as follows:
102
-
103
- * **```includeWarnings```**: ```true``` or ```false```, this determines whether or not warnings should be tested and returned. Defaults to ```true```.
104
-
105
- * **```resourceDir```**: the path to a directory containing resource files (eg. voc.xml) which may be necessary for some schematron tests. Defaults to ```'./'```, the current directory.
106
-
107
- * **```xmlSnippetMaxLength```**: an integer, which is the maximum length of the ```xml``` field in validation results. Defaults to ```200```. Set to ```0``` for unlimited length.
108
-
109
- Here is an example with warnings disabled:
110
-
111
- ```javascript
112
- var results = validator.validate(xml, schematron, { includeWarnings: false });
113
- ```
114
-
115
- ### Cache
116
- The validator uses a cache to store parsed schematrons, an intermediate data structure used to store revelant schematron information. This reduces the runtime of the validator when validating against the same schematron multiple times. You can clear the cache at any time with:
117
- ```javascript
118
- validator.clearCache();
119
- ```
120
-
121
- ---
122
- ## License (MIT)
123
-
124
- Copyright &copy; 2017 [Eric Wadkins](http://www.ericwadkins.com/)
125
-
126
- Copyright &copy; 2022 [Priyaranjan (Raj) Tokachichu](https://github.com/priyaranjan-tokachichu)
127
-
128
- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
129
-
130
- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
131
-
132
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1
+ # [cda-schematron-validator](https://github.com/priyaranjan-tokachichu/cda-schematron-validator)
2
+ ## Release History
3
+ Starting release history with 1.0.7
4
+ ### 1.0.7
5
+ - Added async validate function `validateAsync`
6
+ - Added `testsAsync` to test `validateAsync`
7
+ - Plan to use common functions between sync and async methods in the future release
8
+
9
+ ### 1.0.0 to 1.0.6
10
+ A fork to the original cda-schematron. All credit to Eric Wadkins. Visit the github https://github.com/ewadkins/cda-schematron for the original repo.
11
+
12
+ This is just a cosmetic change with updated node modules, a couple of minor bugs observed, and esversion 6 changes.
13
+
14
+ The changes are fully backward compatible. So, leaving the original documentation as is below.
15
+
16
+ ### New option parameter parsedSchematronMap
17
+ In addition to everything that was possible,
18
+ you can now supply a new option parameter `parsedSchematronMap`. You can create a schematron map as follows.
19
+
20
+ ```javascript
21
+ const fs = require('fs');
22
+ const dom = require('@xmldom/xmldom').DOMParser;
23
+ const { parseSchematron, validate } = require('cda-schematron-validator');
24
+ const schematronString = fs.readFileSync('SchematronFilePath', 'utf-8').toString();
25
+ const schematronDoc = new dom().parseFromString(schematronString);
26
+ const schematronMap = parseSchematron(schematronDoc);
27
+ const options = {
28
+ parsedSchematronMap: schematronMap
29
+ };
30
+ const results = validate('xml string or file path', 'schematron sting, file path or null', options);
31
+ ```
32
+ If a schematron map is provided, the schematron string or path will not be read.
33
+
34
+ To install this npm module, it will be
35
+
36
+ ```
37
+ npm install cda-schematron-validator
38
+ ```
39
+ Mocha VS Code configuratin added to directly execute the test file in `test/tests.js` using VS Code.
40
+
41
+
42
+ # Original Documentation of the cda-schematron
43
+ ## [cda-schematron](https://github.com/ewadkins/cda-schematron)
44
+
45
+ A javascript implementation of schematron testing for XML documents. This specifically resolves a need for a package that allows a quick, reliable install for validating HL7 clinical documents, such as C-CDA.
46
+
47
+ Check out [cda-schematron-server](https://github.com/ewadkins/cda-schematron-server), a server wrapper of **cda-schematron**, for easy schematron validation.
48
+
49
+ ### Validating xml
50
+ ```javascript
51
+ var validator = require('cda-schematron');
52
+
53
+ var xmlPath = 'someFile.xml';
54
+ var schematronPath = 'someFile.sch';
55
+
56
+ var fs = require('fs');
57
+ var xml = fs.readFileSync(xmlPath).toString();
58
+ var schematron = fs.readFileSync(schematronPath).toString();
59
+
60
+ var results = validator.validate(xml, schematron);
61
+ ```
62
+ File paths can also be passed to the validator directly. The following lines all return the same results:
63
+ ```javascript
64
+ var results = validator.validate(xml, schematronPath);
65
+ ```
66
+ ```javascript
67
+ var results = validator.validate(xmlPath, schematron);
68
+ ```
69
+ ```javascript
70
+ var results = validator.validate(xmlPath, schematronPath);
71
+ ```
72
+
73
+ ### Results
74
+ ```results``` is an object containing arrays ```errors```, ```warnings```, and ```ignoreds```.
75
+
76
+ **Errors** and **warnings** are reported as determined by the schematron and test descriptions. They are of the following form:
77
+ ```javascript
78
+ {
79
+ type: type, // "error" or "warning"
80
+ test: test, // xpath test
81
+ simplifiedTest: simplifiedTest, // xpath test with resource values included, if applicable, null otherwise
82
+ description: description, // schematron description of the test case
83
+ line: line, // line number of the violating context
84
+ path: path, // xpath path of the violating context
85
+ patternId: patternId, // schematron-assigned pattern id
86
+ ruleId: ruleId, // schematron-assigned rule id
87
+ assertionId: assertionId, // schematron-assigned assertion id
88
+ context: context, // xpath context of the rule
89
+ xml: xml // xml snippet of the violating context
90
+ }
91
+ ```
92
+
93
+ **Ignored** tests are those that resulted in an exception while running (eg. the test is invalid xpath and could not be parsed properly) and require manual inspection. They are of the following form:
94
+ ```javascript
95
+ {
96
+ errorMessage: errorMessage, // reason for the exception/ignoring the test
97
+ type: type, // "error" or "warning"
98
+ test: test, // xpath test
99
+ simplifiedTest: simplifiedTest, // xpath test with resource values included, if applicable, null otherwise
100
+ description: description, // schematron description of the test case
101
+ patternId: patternId, // schematron-assigned pattern id
102
+ ruleId: ruleId, // schematron-assigned rule id
103
+ assertionId: assertionId, // schematron-assigned assertion id
104
+ context: context, // xpath context of the rule
105
+ }
106
+ ```
107
+
108
+ ### Options
109
+ The ```validate``` function takes in an ```options``` object as an optional third argument. The three fields that can be included in ```options``` are as follows:
110
+
111
+ * **```includeWarnings```**: ```true``` or ```false```, this determines whether or not warnings should be tested and returned. Defaults to ```true```.
112
+
113
+ * **```resourceDir```**: the path to a directory containing resource files (eg. voc.xml) which may be necessary for some schematron tests. Defaults to ```'./'```, the current directory.
114
+
115
+ * **```xmlSnippetMaxLength```**: an integer, which is the maximum length of the ```xml``` field in validation results. Defaults to ```200```. Set to ```0``` for unlimited length.
116
+
117
+ Here is an example with warnings disabled:
118
+
119
+ ```javascript
120
+ var results = validator.validate(xml, schematron, { includeWarnings: false });
121
+ ```
122
+
123
+ ### Cache
124
+ The validator uses a cache to store parsed schematrons, an intermediate data structure used to store revelant schematron information. This reduces the runtime of the validator when validating against the same schematron multiple times. You can clear the cache at any time with:
125
+ ```javascript
126
+ validator.clearCache();
127
+ ```
128
+
129
+ ---
130
+ ## License (MIT)
131
+
132
+ Copyright &copy; 2017 [Eric Wadkins](http://www.ericwadkins.com/)
133
+
134
+ Copyright &copy; 2022 [Priyaranjan (Raj) Tokachichu](https://github.com/priyaranjan-tokachichu)
135
+
136
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
137
+
138
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
139
+
140
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.