robotframework-xmlvalidator 1.0.1__tar.gz → 2.0.0__tar.gz

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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: robotframework-xmlvalidator
3
- Version: 1.0.1
3
+ Version: 2.0.0
4
4
  Summary: A Robot Framework test library for validating XML files against XSD schemas
5
5
  License: Apache-2.0
6
6
  Keywords: robotframework,xml,xsd,validation,test-library,test,testing,test-automation
@@ -51,12 +51,18 @@ Description-Content-Type: text/markdown
51
51
  - [Examples](#examples)
52
52
  - [Using a preloaded schema](#using-a-preloaded-schema)
53
53
  - [Defer schema loading to the test case(s)](#defer-schema-loading-to-the-test-cases)
54
- - [Importing with preloaded XSD that requires a base\_url](#importing-with-preloaded-xsd-that-requires-a-base_url)
55
- - [Importing with custom error\_facets](#importing-with-custom-error_facets)
54
+ - [Importing with preloaded XSD that requires a `base_url`](#importing-with-preloaded-xsd-that-requires-a-base_url)
55
+ - [Importing with custom `error_facets`](#importing-with-custom-error_facets)
56
+ - [Importing with \`fail\_on\_errors=True](#importing-with-fail_on_errorstrue)
56
57
  - [Further examples](#further-examples)
57
58
  - [Using the library](#using-the-library)
58
59
  - [Keyword overview](#keyword-overview)
59
- - [Error collection](#error-collection)
60
+ - [Error collection](#error-collection)
61
+ - [Batch mode](#batch-mode)
62
+ - [Single file mode](#single-file-mode)
63
+ - [Test case status - fail\_on\_error](#test-case-status---fail_on_error)
64
+ - [Dyanmic XSD resolution](#dyanmic-xsd-resolution)
65
+ - [Error collection](#error-collection-1)
60
66
  - [XSD Schema violations.](#xsd-schema-violations)
61
67
  - [Malformed XML](#malformed-xml)
62
68
  - [File-level issues](#file-level-issues)
@@ -64,6 +70,7 @@ Description-Content-Type: text/markdown
64
70
  - [Keyword documentation](#keyword-documentation)
65
71
  - [Keyword example usage](#keyword-example-usage)
66
72
  - [A few basic examples](#a-few-basic-examples)
73
+ - [Demo test suite file as examples](#demo-test-suite-file-as-examples)
67
74
  - [Integration tests as examples](#integration-tests-as-examples)
68
75
  - [Example console output](#example-console-output)
69
76
  - [Example CSV output](#example-csv-output)
@@ -85,6 +92,8 @@ Description-Content-Type: text/markdown
85
92
  - [Continuous Integration \& GitHub templates](#continuous-integration--github-templates)
86
93
  - [Class architecture (Simplified)](#class-architecture-simplified)
87
94
  - [Project Structure](#project-structure)
95
+ - [Changelog](#changelog)
96
+ - [Roadmap](#roadmap)
88
97
  - [License](#license)
89
98
  - [Author](#author)
90
99
 
@@ -157,11 +166,12 @@ See the [Robot Framework Library Scope docs](https://robotframework.org/robotfra
157
166
 
158
167
  ### Library arguments
159
168
 
160
- | Argument | Type | Required? | Description |
161
- |----------------|-------------|-----------|------------------------------------------------------------------------------------|
162
- | `xsd_path` | `str` | No | Path to an XSD file or folder to preload during initialization. In case of a folder, the folder must hold one file only. |
163
- | `base_url` | `str` | No | Base path used to resolve includes/imports within the provided XSD schema. |
164
- | `error_facets` | `list[str]` | No | The attributes of validation errors to collect and report (e.g., `path`, `reason`) |
169
+ | Argument | Type | Required? | Description | Default |
170
+ |-----------------|-------------|-----------|------------------------------------------------------------------------------------------------------------------------|-----------------|
171
+ | `xsd_path` | `str` | No | Path to an XSD file/folder to preload during initialization. In case of a folder, the folder must hold one file only. | None |
172
+ | `base_url` | `str` | No | Base path used to resolve includes/imports within the provided XSD schema. | None |
173
+ | `error_facets` | `list[str]` | No | The attributes of validation errors to collect and report (e.g., `path`, `reason`) | [path, reason] |
174
+ | `fail_on_error` | `bool` | No | Whether to fail the test case if one or more XML validation errors are found. Can be overridden per keyword call. | True |
165
175
 
166
176
  ### Examples
167
177
 
@@ -178,7 +188,7 @@ Library xmlvalidator xsd_path=path/to/schema.xsd
178
188
  Library xmlvalidator
179
189
  ```
180
190
 
181
- #### Importing with preloaded XSD that requires a base_url
191
+ #### Importing with preloaded XSD that requires a `base_url`
182
192
 
183
193
  ```robotframework
184
194
  Library xmlvalidator xsd_path=path/to/schema_with_include.xsd
@@ -187,7 +197,7 @@ Library xmlvalidator xsd_path=path/to/schema_with_include.xsd
187
197
 
188
198
  Use `base_url` when your XSD uses `<xs:include>` or `<xs:import>` with relative paths.
189
199
 
190
- #### Importing with custom error_facets
200
+ #### Importing with custom `error_facets`
191
201
 
192
202
  Use the `error_facets` argument to control which attributes of detected errors will be collected and reported.
193
203
 
@@ -206,6 +216,21 @@ Library xmlvalidator xsd_path=schemas/schema.xsd
206
216
  ... error_facets=value, namespaces
207
217
  ```
208
218
 
219
+ #### Importing with `fail_on_errors=True
220
+
221
+ The fail_on_errors argument controls whether a test case should fail if XML validation errors are detected.
222
+
223
+ It defaults to True.
224
+
225
+ The library's batch validation behavior remains unchanged. That is, `fail_on_errors=True` does *not* short-circuit the validation process in any way.
226
+
227
+ Set `fail_on_errors=False` to log validation issues without failing the test. This is useful for:
228
+
229
+ - Non-blocking checks in dashboards or QA reports.
230
+ - Legacy or transitional systems where some invalid files are expected.
231
+ - Schema discovery or diagnostics, where conformance isn’t yet enforced.
232
+ - Soft rollout of stricter validation rules, allowing time to adapt.
233
+
209
234
  #### Further examples
210
235
 
211
236
  See also the [library initialization Robot test file](test/integration/01_library_initialization.robot).
@@ -216,39 +241,63 @@ See also the [library initialization Robot test file](test/integration/01_librar
216
241
 
217
242
  ### Keyword overview
218
243
 
219
- | Keyword | Description |
220
- |--------------------------|-------------|
244
+ Thi section merely provides a short summary of the library's capabilities.
245
+
246
+ For more details, please see the [keyword documentation](https://michaelhallik.github.io/robotframework-xmlvalidator/XmlValidator.html).
247
+
248
+ | Keyword | Description |
249
+ |--------------------------|---------------------------------------------------------------------|
221
250
  | `Validate Xml Files` | Validate one or more XML files against one or more XSD schema files |
222
- | `Reset Schema` | Clear the currently loaded XSD schema |
223
- | `Reset Errors` | Clear the set of collected errors |
224
- | `Get Schema` | Get the current schema name or object |
225
- | `Log Schema` | Log the currently loaded schema |
226
- | `Get Error Facets` | Returns a list of the currently active error facets |
227
- | `Reset Error Facets` | Reset the error facets to default (`path`, `reason`) |
251
+ | `Reset Schema` | Clear the currently loaded XSD schema |
252
+ | `Reset Errors` | Clear the set of collected errors |
253
+ | `Get Schema` | Get the current schema name or object |
254
+ | `Log Schema` | Log the currently loaded schema |
255
+ | `Get Error Facets` | Returns a list of the currently active error facets |
256
+ | `Reset Error Facets` | Reset the error facets to default (`path`, `reason`) |
228
257
 
229
258
  The main keyword is `Validate Xml Files`. The other keywords are convenience/helper functions, e.g. 'Reset Error Facets'.
230
259
 
260
+ #### Error collection
261
+
231
262
  The `Validate Xml Files` validates one or more XML files against one or more XSD schema files and collects and reports all encountered errors.
232
263
 
233
- The type of error that the keyword can detect is not limited to XSD violations, but may also pertain to malformed XML files (e.g. parse errors), empty files, unmatched XML files (no XSD match found), etc.
264
+ The type of error that the keyword can detect is not limited to XSD violations, but may also pertain to malformed XML files, empty files, unmatched XML files (no XSD match found), etc.
234
265
 
235
266
  Errors that result from malformed XML files or from XSD violations support detailed error reporting. Using the `error_facets` argument you may specify the details the keyword should collect and report about captured errors.
236
267
 
237
- When operating in batch mode, the `Validate Xml Files` keyword always validates the entire set of passed XML files.
268
+ #### Batch mode
238
269
 
239
- That is, when it encounters an error in a file, it does not fail. Rather, it collects the error details (as determined by the `error_facets` arg) and then continues validating the current file as well as any subsequent file(s).
270
+ The `Validate Xml Files` keyword always validates the entire set of passed XML files.
271
+
272
+ That is, when it encounters an error in a file, it does not fail and stop execution. Rather, it collects the error details (as determined by the `error_facets` arg) and then continues validating the current file as well as any subsequent file(s).
240
273
 
241
274
  In that fashion the keyword works through the entire set of files.
242
275
 
243
- Once all files are processed it will log a summary of the test run and then proceed to report all collected errors in the console, in the RF log and, optionally, in the form of a CSV file.
276
+ Once *all* files are processed it will log a summary of the test run and then proceed to report all collected errors in the console, in the RF log and, optionally, in the form of a CSV file.
244
277
 
245
- However, in case you want your test case to fail when one or more errors have been detected, you can use the ``fail_on_errors`` (bool) argument to make it so. It defaults to False. When setting it to True, the keyword will still check each XML file (and collect possible errors), but after it has thus processed the batch, it will fail if one or more errors will have been detected.
278
+ For example:
279
+ - If you validate fifteen XML files and five of them contain schema violations or other errors, all files will still be processed.
280
+ - Errors are simply collected throughout the run and reported collectively, only after the final file has been (fully) processed.
281
+ - The test case will fail (assuming `fail_on_errors=True`) only after all files have been checked, ensuring comprehensive diagnostics.
246
282
 
247
- The keyword further supports the dynamic matching (i.e. pairing) of XML and XSD files, using either a 'by filename' or a 'by namespace' strategy. That means you can simply pass the paths to a folder containing XML files and to a folder containing XSD files and the keyword will determine which XSD schema file to use for each XML file. If the XML and XSD files reside in the same folder, you only have to pass one folder path. When no matching XSD schema could be identified for an XML file, this will be integrated into the mentioned summary and error reporting (the keyword will not fail).
283
+ #### Single file mode
248
284
 
249
285
  Of course, you may also refer to specific XML/XSD files (instead of to folders). In that case, no matching will be attempted, but the keyword will simply try to validate the specified XML file against the specified XSD file.
250
286
 
251
- For more details, please see the [keyword documentation](https://michaelhallik.github.io/robotframework-xmlvalidator/XmlValidator.html).
287
+ Actually, almost anything goes:
288
+
289
+ - one folder with: one or more XML files and one or more XSD files
290
+ - one folder with one or more XML files and another folder with one or more XSD files
291
+ - one folder with one or more XML files and a single XSD file
292
+ - a single XML file and a sigle XSD file
293
+
294
+ #### Test case status - fail_on_error
295
+
296
+ A test case that has resulted in the collection of one or more errors (of whatever type) will receive a status of FAIL. You can use the ``fail_on_errors`` (bool) argument to change this default behaviour. When set to `False`, the test cases's status will always be PASS, regardless whether errors were collected or not.
297
+
298
+ #### Dyanmic XSD resolution
299
+
300
+ The keyword further supports the dynamic matching (i.e. pairing) of XML and XSD files, using either a 'by filename' or a 'by namespace' strategy. That means you can simply pass the paths to a folder containing XML files and to a folder containing XSD files and the keyword will determine which XSD schema file to use for each XML file. If the XML and XSD files reside in the same folder, you only have to pass one folder path. When no matching XSD schema could be identified for an XML file, this will be integrated into the mentioned summary and error reporting (the keyword will not fail).
252
301
 
253
302
  ### Error collection
254
303
 
@@ -333,9 +382,9 @@ General errors that do not pertain to syntax or schema issues:
333
382
 
334
383
  #### Final note on error collection
335
384
 
336
- On account of the purpose of this library, all encountered errors (regardless the involved types) are collected and reported. The validator analyzes all files, collects encountered errors (if any) and, finally, reports the results of the run in the console and in the Robot Framework log
385
+ On account of the purpose of this library, all encountered errors (regardless the involved types) are collected and reported. The validator analyzes all files, collects encountered errors (if any) and, finally, reports the results of the run in the console and in the Robot Framework log.
337
386
 
338
- If you want the test run to receive a FAIL status when, at the end of test run, one or more errors have been found, then set: `fail_on_errors=True`.
387
+ Every test case in which one or more errors have been collected, will receive status FAIL unless `fail_on_errors=True` (see earlier explanations).
339
388
 
340
389
  ### Keyword documentation
341
390
 
@@ -384,6 +433,10 @@ Validate Folder With Multiple Schemas By File Name
384
433
  Validate Xml Files ${FOLDER_MULTIPLE_XML_XSD_FN} xsd_search_strategy=by_file_name
385
434
  ```
386
435
 
436
+ #### Demo test suite file as examples
437
+
438
+ See the [demo test suite](test/demo/demo.robot) for a demo test suite that demonstrates the most important features of the library in a concise fashion.
439
+
387
440
  #### Integration tests as examples
388
441
 
389
442
  Note that the [integration test](test/integration) folder contains seven Robot Framework test suite files.
@@ -772,6 +825,18 @@ requirements.txt # Requirements file for users (pip)
772
825
 
773
826
  ---
774
827
 
828
+ ## Changelog
829
+
830
+ For a list of changes across versions, including recent behavioral changes in validation logic, see the [CHANGELOG](https://github.com/MichaelHallik/robotframework-xmlvalidator/blob/main/CHANGELOG.md).
831
+
832
+ ---
833
+
834
+ ## Roadmap
835
+
836
+ See the [project roadmap](ROADMAP.md) for upcoming features and ideas.
837
+
838
+ ---
839
+
775
840
  ## License
776
841
 
777
842
  Licensed under the Apache License 2.0. See [LICENSE](LICENSE).
@@ -24,12 +24,18 @@
24
24
  - [Examples](#examples)
25
25
  - [Using a preloaded schema](#using-a-preloaded-schema)
26
26
  - [Defer schema loading to the test case(s)](#defer-schema-loading-to-the-test-cases)
27
- - [Importing with preloaded XSD that requires a base\_url](#importing-with-preloaded-xsd-that-requires-a-base_url)
28
- - [Importing with custom error\_facets](#importing-with-custom-error_facets)
27
+ - [Importing with preloaded XSD that requires a `base_url`](#importing-with-preloaded-xsd-that-requires-a-base_url)
28
+ - [Importing with custom `error_facets`](#importing-with-custom-error_facets)
29
+ - [Importing with \`fail\_on\_errors=True](#importing-with-fail_on_errorstrue)
29
30
  - [Further examples](#further-examples)
30
31
  - [Using the library](#using-the-library)
31
32
  - [Keyword overview](#keyword-overview)
32
- - [Error collection](#error-collection)
33
+ - [Error collection](#error-collection)
34
+ - [Batch mode](#batch-mode)
35
+ - [Single file mode](#single-file-mode)
36
+ - [Test case status - fail\_on\_error](#test-case-status---fail_on_error)
37
+ - [Dyanmic XSD resolution](#dyanmic-xsd-resolution)
38
+ - [Error collection](#error-collection-1)
33
39
  - [XSD Schema violations.](#xsd-schema-violations)
34
40
  - [Malformed XML](#malformed-xml)
35
41
  - [File-level issues](#file-level-issues)
@@ -37,6 +43,7 @@
37
43
  - [Keyword documentation](#keyword-documentation)
38
44
  - [Keyword example usage](#keyword-example-usage)
39
45
  - [A few basic examples](#a-few-basic-examples)
46
+ - [Demo test suite file as examples](#demo-test-suite-file-as-examples)
40
47
  - [Integration tests as examples](#integration-tests-as-examples)
41
48
  - [Example console output](#example-console-output)
42
49
  - [Example CSV output](#example-csv-output)
@@ -58,6 +65,8 @@
58
65
  - [Continuous Integration \& GitHub templates](#continuous-integration--github-templates)
59
66
  - [Class architecture (Simplified)](#class-architecture-simplified)
60
67
  - [Project Structure](#project-structure)
68
+ - [Changelog](#changelog)
69
+ - [Roadmap](#roadmap)
61
70
  - [License](#license)
62
71
  - [Author](#author)
63
72
 
@@ -130,11 +139,12 @@ See the [Robot Framework Library Scope docs](https://robotframework.org/robotfra
130
139
 
131
140
  ### Library arguments
132
141
 
133
- | Argument | Type | Required? | Description |
134
- |----------------|-------------|-----------|------------------------------------------------------------------------------------|
135
- | `xsd_path` | `str` | No | Path to an XSD file or folder to preload during initialization. In case of a folder, the folder must hold one file only. |
136
- | `base_url` | `str` | No | Base path used to resolve includes/imports within the provided XSD schema. |
137
- | `error_facets` | `list[str]` | No | The attributes of validation errors to collect and report (e.g., `path`, `reason`) |
142
+ | Argument | Type | Required? | Description | Default |
143
+ |-----------------|-------------|-----------|------------------------------------------------------------------------------------------------------------------------|-----------------|
144
+ | `xsd_path` | `str` | No | Path to an XSD file/folder to preload during initialization. In case of a folder, the folder must hold one file only. | None |
145
+ | `base_url` | `str` | No | Base path used to resolve includes/imports within the provided XSD schema. | None |
146
+ | `error_facets` | `list[str]` | No | The attributes of validation errors to collect and report (e.g., `path`, `reason`) | [path, reason] |
147
+ | `fail_on_error` | `bool` | No | Whether to fail the test case if one or more XML validation errors are found. Can be overridden per keyword call. | True |
138
148
 
139
149
  ### Examples
140
150
 
@@ -151,7 +161,7 @@ Library xmlvalidator xsd_path=path/to/schema.xsd
151
161
  Library xmlvalidator
152
162
  ```
153
163
 
154
- #### Importing with preloaded XSD that requires a base_url
164
+ #### Importing with preloaded XSD that requires a `base_url`
155
165
 
156
166
  ```robotframework
157
167
  Library xmlvalidator xsd_path=path/to/schema_with_include.xsd
@@ -160,7 +170,7 @@ Library xmlvalidator xsd_path=path/to/schema_with_include.xsd
160
170
 
161
171
  Use `base_url` when your XSD uses `<xs:include>` or `<xs:import>` with relative paths.
162
172
 
163
- #### Importing with custom error_facets
173
+ #### Importing with custom `error_facets`
164
174
 
165
175
  Use the `error_facets` argument to control which attributes of detected errors will be collected and reported.
166
176
 
@@ -179,6 +189,21 @@ Library xmlvalidator xsd_path=schemas/schema.xsd
179
189
  ... error_facets=value, namespaces
180
190
  ```
181
191
 
192
+ #### Importing with `fail_on_errors=True
193
+
194
+ The fail_on_errors argument controls whether a test case should fail if XML validation errors are detected.
195
+
196
+ It defaults to True.
197
+
198
+ The library's batch validation behavior remains unchanged. That is, `fail_on_errors=True` does *not* short-circuit the validation process in any way.
199
+
200
+ Set `fail_on_errors=False` to log validation issues without failing the test. This is useful for:
201
+
202
+ - Non-blocking checks in dashboards or QA reports.
203
+ - Legacy or transitional systems where some invalid files are expected.
204
+ - Schema discovery or diagnostics, where conformance isn’t yet enforced.
205
+ - Soft rollout of stricter validation rules, allowing time to adapt.
206
+
182
207
  #### Further examples
183
208
 
184
209
  See also the [library initialization Robot test file](test/integration/01_library_initialization.robot).
@@ -189,39 +214,63 @@ See also the [library initialization Robot test file](test/integration/01_librar
189
214
 
190
215
  ### Keyword overview
191
216
 
192
- | Keyword | Description |
193
- |--------------------------|-------------|
217
+ Thi section merely provides a short summary of the library's capabilities.
218
+
219
+ For more details, please see the [keyword documentation](https://michaelhallik.github.io/robotframework-xmlvalidator/XmlValidator.html).
220
+
221
+ | Keyword | Description |
222
+ |--------------------------|---------------------------------------------------------------------|
194
223
  | `Validate Xml Files` | Validate one or more XML files against one or more XSD schema files |
195
- | `Reset Schema` | Clear the currently loaded XSD schema |
196
- | `Reset Errors` | Clear the set of collected errors |
197
- | `Get Schema` | Get the current schema name or object |
198
- | `Log Schema` | Log the currently loaded schema |
199
- | `Get Error Facets` | Returns a list of the currently active error facets |
200
- | `Reset Error Facets` | Reset the error facets to default (`path`, `reason`) |
224
+ | `Reset Schema` | Clear the currently loaded XSD schema |
225
+ | `Reset Errors` | Clear the set of collected errors |
226
+ | `Get Schema` | Get the current schema name or object |
227
+ | `Log Schema` | Log the currently loaded schema |
228
+ | `Get Error Facets` | Returns a list of the currently active error facets |
229
+ | `Reset Error Facets` | Reset the error facets to default (`path`, `reason`) |
201
230
 
202
231
  The main keyword is `Validate Xml Files`. The other keywords are convenience/helper functions, e.g. 'Reset Error Facets'.
203
232
 
233
+ #### Error collection
234
+
204
235
  The `Validate Xml Files` validates one or more XML files against one or more XSD schema files and collects and reports all encountered errors.
205
236
 
206
- The type of error that the keyword can detect is not limited to XSD violations, but may also pertain to malformed XML files (e.g. parse errors), empty files, unmatched XML files (no XSD match found), etc.
237
+ The type of error that the keyword can detect is not limited to XSD violations, but may also pertain to malformed XML files, empty files, unmatched XML files (no XSD match found), etc.
207
238
 
208
239
  Errors that result from malformed XML files or from XSD violations support detailed error reporting. Using the `error_facets` argument you may specify the details the keyword should collect and report about captured errors.
209
240
 
210
- When operating in batch mode, the `Validate Xml Files` keyword always validates the entire set of passed XML files.
241
+ #### Batch mode
211
242
 
212
- That is, when it encounters an error in a file, it does not fail. Rather, it collects the error details (as determined by the `error_facets` arg) and then continues validating the current file as well as any subsequent file(s).
243
+ The `Validate Xml Files` keyword always validates the entire set of passed XML files.
244
+
245
+ That is, when it encounters an error in a file, it does not fail and stop execution. Rather, it collects the error details (as determined by the `error_facets` arg) and then continues validating the current file as well as any subsequent file(s).
213
246
 
214
247
  In that fashion the keyword works through the entire set of files.
215
248
 
216
- Once all files are processed it will log a summary of the test run and then proceed to report all collected errors in the console, in the RF log and, optionally, in the form of a CSV file.
249
+ Once *all* files are processed it will log a summary of the test run and then proceed to report all collected errors in the console, in the RF log and, optionally, in the form of a CSV file.
217
250
 
218
- However, in case you want your test case to fail when one or more errors have been detected, you can use the ``fail_on_errors`` (bool) argument to make it so. It defaults to False. When setting it to True, the keyword will still check each XML file (and collect possible errors), but after it has thus processed the batch, it will fail if one or more errors will have been detected.
251
+ For example:
252
+ - If you validate fifteen XML files and five of them contain schema violations or other errors, all files will still be processed.
253
+ - Errors are simply collected throughout the run and reported collectively, only after the final file has been (fully) processed.
254
+ - The test case will fail (assuming `fail_on_errors=True`) only after all files have been checked, ensuring comprehensive diagnostics.
219
255
 
220
- The keyword further supports the dynamic matching (i.e. pairing) of XML and XSD files, using either a 'by filename' or a 'by namespace' strategy. That means you can simply pass the paths to a folder containing XML files and to a folder containing XSD files and the keyword will determine which XSD schema file to use for each XML file. If the XML and XSD files reside in the same folder, you only have to pass one folder path. When no matching XSD schema could be identified for an XML file, this will be integrated into the mentioned summary and error reporting (the keyword will not fail).
256
+ #### Single file mode
221
257
 
222
258
  Of course, you may also refer to specific XML/XSD files (instead of to folders). In that case, no matching will be attempted, but the keyword will simply try to validate the specified XML file against the specified XSD file.
223
259
 
224
- For more details, please see the [keyword documentation](https://michaelhallik.github.io/robotframework-xmlvalidator/XmlValidator.html).
260
+ Actually, almost anything goes:
261
+
262
+ - one folder with: one or more XML files and one or more XSD files
263
+ - one folder with one or more XML files and another folder with one or more XSD files
264
+ - one folder with one or more XML files and a single XSD file
265
+ - a single XML file and a sigle XSD file
266
+
267
+ #### Test case status - fail_on_error
268
+
269
+ A test case that has resulted in the collection of one or more errors (of whatever type) will receive a status of FAIL. You can use the ``fail_on_errors`` (bool) argument to change this default behaviour. When set to `False`, the test cases's status will always be PASS, regardless whether errors were collected or not.
270
+
271
+ #### Dyanmic XSD resolution
272
+
273
+ The keyword further supports the dynamic matching (i.e. pairing) of XML and XSD files, using either a 'by filename' or a 'by namespace' strategy. That means you can simply pass the paths to a folder containing XML files and to a folder containing XSD files and the keyword will determine which XSD schema file to use for each XML file. If the XML and XSD files reside in the same folder, you only have to pass one folder path. When no matching XSD schema could be identified for an XML file, this will be integrated into the mentioned summary and error reporting (the keyword will not fail).
225
274
 
226
275
  ### Error collection
227
276
 
@@ -306,9 +355,9 @@ General errors that do not pertain to syntax or schema issues:
306
355
 
307
356
  #### Final note on error collection
308
357
 
309
- On account of the purpose of this library, all encountered errors (regardless the involved types) are collected and reported. The validator analyzes all files, collects encountered errors (if any) and, finally, reports the results of the run in the console and in the Robot Framework log
358
+ On account of the purpose of this library, all encountered errors (regardless the involved types) are collected and reported. The validator analyzes all files, collects encountered errors (if any) and, finally, reports the results of the run in the console and in the Robot Framework log.
310
359
 
311
- If you want the test run to receive a FAIL status when, at the end of test run, one or more errors have been found, then set: `fail_on_errors=True`.
360
+ Every test case in which one or more errors have been collected, will receive status FAIL unless `fail_on_errors=True` (see earlier explanations).
312
361
 
313
362
  ### Keyword documentation
314
363
 
@@ -357,6 +406,10 @@ Validate Folder With Multiple Schemas By File Name
357
406
  Validate Xml Files ${FOLDER_MULTIPLE_XML_XSD_FN} xsd_search_strategy=by_file_name
358
407
  ```
359
408
 
409
+ #### Demo test suite file as examples
410
+
411
+ See the [demo test suite](test/demo/demo.robot) for a demo test suite that demonstrates the most important features of the library in a concise fashion.
412
+
360
413
  #### Integration tests as examples
361
414
 
362
415
  Note that the [integration test](test/integration) folder contains seven Robot Framework test suite files.
@@ -745,6 +798,18 @@ requirements.txt # Requirements file for users (pip)
745
798
 
746
799
  ---
747
800
 
801
+ ## Changelog
802
+
803
+ For a list of changes across versions, including recent behavioral changes in validation logic, see the [CHANGELOG](https://github.com/MichaelHallik/robotframework-xmlvalidator/blob/main/CHANGELOG.md).
804
+
805
+ ---
806
+
807
+ ## Roadmap
808
+
809
+ See the [project roadmap](ROADMAP.md) for upcoming features and ideas.
810
+
811
+ ---
812
+
748
813
  ## License
749
814
 
750
815
  Licensed under the Apache License 2.0. See [LICENSE](LICENSE).
@@ -1,7 +1,7 @@
1
1
  # General.
2
2
  [tool.poetry]
3
3
  name = "robotframework-xmlvalidator"
4
- version = "1.0.1"
4
+ version = "2.0.0"
5
5
  description = "A Robot Framework test library for validating XML files against XSD schemas"
6
6
  authors = ["Michael Hallik <hallik.michael@gmail.com>"]
7
7
  license = "Apache-2.0"
@@ -98,10 +98,10 @@ class XmlValidator:
98
98
 
99
99
  When operating in batch mode, the ``Validate Xml Files`` keyword
100
100
  always validates the entire set of passed XML files. That is, when
101
- it encounters an error in a file, it does not simply fail. Rather,
102
- it collects the error details (as determined by the error_facets
103
- arg) and then continues validating the current file as well as any
104
- subsequent file(s).
101
+ it encounters an error in a file, it does not simply then fail.
102
+ Rather, it collects the error details (as determined by the
103
+ error_facets arg) and then continues validating the current file as
104
+ well as any subsequent file(s).
105
105
 
106
106
  In that fashion the keyword works through the entire set of files.
107
107
 
@@ -158,12 +158,14 @@ class XmlValidator:
158
158
  - Namespace errors.
159
159
  - Etc.
160
160
 
161
- - Captures malformed XML.
161
+ - Captures malformed XML (e.g. missing closing tag, encoding
162
+ issues).
162
163
  - Handles edge cases like empty files or XML files that could not be
163
164
  matched to an XSD schema file.
164
- - Does not fail on errors, but collects encountered errors in all
165
- files and reports them in a structured format in the console and
166
- RF log.
165
+ - Does not immediately fail on errors, but collects encountered all
166
+ errors in all files and reports them in a structured format in the
167
+ console and RF log. Only *then* fails (assuming one or more
168
+ errors have been collected).
167
169
  - Supports specifying the details that should be collected for
168
170
  encountered errors.
169
171
  - Optionally exports the error report to a CSV file, providing the
@@ -236,23 +238,13 @@ class XmlValidator:
236
238
  Enables resolution of schema imports/includes via a custom base URL,
237
239
  via the ``base_url`` arg.
238
240
 
239
- Use ``base_url`` when your XSD uses <xs:include> or <xs:import> with
240
- relative paths.
241
+ Use ``base_url`` when your XSD uses ``<xs:include>`` or ``<xs:import>``
242
+ with relative paths.
241
243
 
242
244
  You can pass ``base_url`` with the library import (together with
243
245
  passing ``xsd_path``) and/or when calling ``Validate Xml Files``
244
246
  with ``xsd_path``.
245
247
 
246
- ** Optional test case fail **
247
-
248
- The ``Validate Xml Files`` keyword collects one or more errors for
249
- one or more XML files. As mentioned earlier, the keyword is designed
250
- so as to not fail upon encountering errors.
251
-
252
- However, in case you want your test case to fail when one or more
253
- errors have been detected, you can use the ``fail_on_errors`` (bool)
254
- argument to make it so. It defaults to ${False}.
255
-
256
248
  **Basic usage examples**
257
249
 
258
250
  For a comprehensive set of example test cases, please see the
@@ -266,6 +258,18 @@ class XmlValidator:
266
258
  It further contains a detailed instruction on
267
259
  `how to run Robot Framework tests <https://github.com/MichaelHallik/robotframework-xmlvalidator/blob/main/test/_doc/integration/README.md>`_.
268
260
 
261
+ Finally, the repo also contains a `demo test suite file <https://github.com/MichaelHallik/robotframework-xmlvalidator/blob/main/test/demo/demo.robot>`_ containing
262
+ eight self-contained test cases to demonstrates the following features:
263
+
264
+ - Single and batch XML validation
265
+ - Schema matching by filename and namespace
266
+ - Custom error facets
267
+ - Malformed XML handling
268
+ - XSD includes/imports
269
+ - CSV export
270
+
271
+ A test suite file may look like the following:
272
+
269
273
  .. code:: robotframework
270
274
 
271
275
  *** Settings ***
@@ -361,21 +365,8 @@ class XmlValidator:
361
365
  [ WARN ] XML is invalid:
362
366
  [ WARN ] Error #0:
363
367
  [ WARN ] reason: No matching XSD found for: no_xsd_match_2.xml.
364
- Validation errors exported to 'C:\\test\\01_Advanced_Validation\\errors_2025-03-29_13-54-46-552150.csv'.
365
- Total_files validated: 11.
366
- Valid files: 6.
367
- Invalid files: 5
368
- 01 Advanced Validation:: Demo XML validation | PASS |
369
- 21 errors have been detected.
370
- ========================================================
371
- 01 Advanced Validation:: Demo XML validation | PASS |
372
- 1 test, 1 passed, 0 failed
373
-
374
- In case ``fail_on_errors`` is True, the console output will look like this:
375
-
376
- .. code:: console
377
-
378
- Validation errors exported to 'C:\\test\\01_Advanced_Validation\\errors_2025-03-29_13-54-46-552150.csv'.
368
+ Validation errors exported to:
369
+ 'C:\\test\\01_Advanced_Validation\\errors_2025-03-29_13-54-46-552150.csv'.
379
370
  Total_files validated: 11.
380
371
  Valid files: 6.
381
372
  Invalid files: 5.
@@ -384,8 +375,8 @@ class XmlValidator:
384
375
  ========================================================
385
376
  01 Advanced Validation:: Demo XML validation | FAIL |
386
377
  1 test, 0 passed, 1 failed
387
-
388
- The corresponding CSV output would in both cases look like:
378
+
379
+ The corresponding CSV output will look like:
389
380
 
390
381
  .. code:: text
391
382
 
@@ -402,16 +393,17 @@ class XmlValidator:
402
393
 
403
394
  """
404
395
 
405
- __version__ = '1.0.1'
396
+ __version__ = '2.0.0'
406
397
  ROBOT_LIBRARY_DOC_FORMAT = 'reST'
407
398
  nr_instances = 0
408
399
 
409
400
  def __init__(
410
401
  self,
411
- xsd_path: Optional[str|Path] = None,
412
- base_url: Optional[str] = None,
413
- error_facets: Optional[List[str]] = None
414
- ) -> None:
402
+ xsd_path: str | Path | None = None,
403
+ base_url: str | None = None,
404
+ error_facets: List[str] | None = None,
405
+ fail_on_errors: bool = True
406
+ ) -> None:
415
407
  """
416
408
  **Library Scope**
417
409
 
@@ -421,16 +413,19 @@ class XmlValidator:
421
413
 
422
414
  **Library Arguments**
423
415
 
424
- +--------------+--------------+-----------+---------------------------------------------------------------------------------------------+
425
- | Argument | Type | Required | Description |
426
- +==============+==============+===========+=============================================================================================+
427
- | xsd_path | str | No | Path to an XSD file or folder to preload during initialization. |
428
- | | | | In case of a folder, the folder must hold one file only. |
429
- +--------------+--------------+-----------+---------------------------------------------------------------------------------------------+
430
- | base_url | str | No | Base path used to resolve includes/imports within the provided XSD schema. |
431
- +--------------+--------------+-----------+---------------------------------------------------------------------------------------------+
432
- | error_facets | list of str | No | The attributes of validation errors to collect and report. E.g. ``path``, ``reason``. |
433
- +--------------+--------------+-----------+---------------------------------------------------------------------------------------------+
416
+ +---------------+-------------+----------+---------------------------------------------------------------------------------------------+----------------+
417
+ | Argument | Type | Required | Description | Default |
418
+ +===============+=============+==========+=============================================================================================+================+
419
+ | xsd_path | str | No | Path to an XSD file or folder to preload during initialization. | None |
420
+ | | | | In case of a folder, the folder must hold one file only. | |
421
+ +---------------+-------------+----------+---------------------------------------------------------------------------------------------+----------------+
422
+ | base_url | str | No | Base path used to resolve includes/imports within the provided XSD schema. | None |
423
+ +---------------+-------------+----------+---------------------------------------------------------------------------------------------+----------------+
424
+ | error_facets | list of str | No | The attributes of validation errors to collect and report. E.g. ``path``, ``reason``. | [path, reason] |
425
+ +---------------+-------------+----------+---------------------------------------------------------------------------------------------+----------------+
426
+ | fail_on_error | bool | No | Whether to fail the test case if one or more XML validation errors are found. | True |
427
+ | | | | Can be overridden per keyword call. | |
428
+ +---------------+-------------+----------+---------------------------------------------------------------------------------------------+----------------+
434
429
 
435
430
  All arguments are optional.
436
431
 
@@ -485,6 +480,30 @@ class XmlValidator:
485
480
 
486
481
  See the introduction for more details on the purpose and usage
487
482
  of error facets.
483
+
484
+ ``fail_on_error``
485
+
486
+ The ``fail_on_errors`` argument controls whether a test case
487
+ should fail if one or more XML validation errors are detected.
488
+ It defaults to True. A test case that has resulted in the
489
+ collection of one or more errors (of whatever type) will then
490
+ receive a status of FAIL.
491
+
492
+ You can use the ``fail_on_errors`` argument to change this
493
+ default behaviour. When set to False, a test cases's status will
494
+ always be PASS, regardless whether errors were collected or not.
495
+
496
+ This may be useful for:
497
+
498
+ - Non-blocking checks in dashboards or QA reports.
499
+ - Legacy or transitional systems where some invalid files are expected.
500
+ - Schema discovery or diagnostics, where conformance isn’t yet enforced.
501
+ - Soft rollout of stricter validation rules, allowing time to adapt.
502
+
503
+ Note that with ``fail_on_error=True`` the library's batch
504
+ validation behavior remains unchanged by the latter. That is,
505
+ fail_on_errors=True does not short-circuit the validation
506
+ process in any way.
488
507
 
489
508
  **Examples**
490
509
 
@@ -530,6 +549,8 @@ class XmlValidator:
530
549
  For more examples see the project's
531
550
  `Robot Framework integration test suite <https://github.com/MichaelHallik/robotframework-xmlvalidator/blob/main/test/integration/01_library_initialization.robot>`_.
532
551
 
552
+ And also the `demo test suite file <https://github.com/MichaelHallik/robotframework-xmlvalidator/blob/main/test/demo/demo.robot>`_.
553
+
533
554
  **Raises**
534
555
 
535
556
  +---------------+--------------------------------------------------------------+
@@ -550,20 +571,27 @@ class XmlValidator:
550
571
  self.validator_results = ValidatorResultRecorder()
551
572
  # Initialize the xsd schema from the xsd_path, if provided.
552
573
  self.schema = self._try_load_initial_schema(
553
- xsd_path=xsd_path,
554
- base_url=base_url
555
- )
574
+ xsd_path=xsd_path, base_url=base_url
575
+ )
556
576
  # Set the error facets to collect for failed XML validations.
557
577
  self.error_facets = error_facets if error_facets else [
558
578
  'path', 'reason'
559
- ]
579
+ ]
560
580
  logger.info(
561
581
  f"Collecting error facets: {self.error_facets}.",
562
582
  also_console=True
563
- )
583
+ )
584
+ # Set the validation strictness.
585
+ self.fail_on_errors = fail_on_errors
586
+ logger.info(
587
+ f"Fail on errors: {self.fail_on_errors}.", also_console=True
588
+ )
589
+ # Report readiness.
564
590
  logger.info("XML Validator ready for use!", also_console=True)
565
591
  self.nr_instances += 1
566
- logger.info(f'Number of library instances: {self.nr_instances}.')
592
+ logger.info(
593
+ f'Number of library instances: {self.nr_instances}.'
594
+ )
567
595
 
568
596
  def _determine_validations(
569
597
  self,
@@ -784,15 +812,15 @@ class XmlValidator:
784
812
  "No schema: provide an XSD path during keyword call(s)."
785
813
  )
786
814
  if self.schema and not xsd_path :
787
- logger.info(
788
- f'No new schema set: keeping existing schema {self.schema}.'
789
- )
815
+ # logger.info(
816
+ # f'No new schema set: keeping existing schema {self.schema}.'
817
+ # )
790
818
  return ValidatorResult(success=True, value=self.schema)
791
819
  if not self.schema and xsd_path:
792
820
  logger.info(f'Setting schema file: {xsd_path}.', also_console=True)
793
821
  if self.schema and xsd_path:
794
822
  logger.info(
795
- f'Setting new schema file: {xsd_path}.',
823
+ f'\tUsing schema: {xsd_path}.',
796
824
  also_console=True
797
825
  )
798
826
  return self._load_schema(xsd_path, base_url) # pyright: ignore
@@ -895,13 +923,13 @@ class XmlValidator:
895
923
  # Catch and handle any exception.
896
924
  except Exception as err: # pylint: disable=W0718:broad-exception-caught
897
925
  # Inform the user.
898
- logger.warn('Processing XML file failed.')
926
+ logger.info('\t\tProcessing XML file failed.')
899
927
  # Collect the error to be mapped to the xml file.
900
928
  validations[xml_file_path] = err
901
929
  continue
902
930
  # Test each XSD file for a matching namespace.
903
931
  for xsd_file_path in xsd_file_paths:
904
- logger.info(f"Testing schema: {xsd_file_path}.")
932
+ logger.info(f"\t\tTesting schema: {xsd_file_path}.")
905
933
  # Load the schema.
906
934
  result = self._load_schema(
907
935
  xsd_file_path, base_url=base_url
@@ -929,7 +957,7 @@ class XmlValidator:
929
957
  logger.info(f"\t\t\tTesting file name: {xsd_file_path}.")
930
958
  # Compare the XSD/XML file names.
931
959
  if xsd_file_path.stem == xml_file_path.stem:
932
- logger.info("\t\t\tFound match.")
960
+ logger.info("\t\tFound match.")
933
961
  # Assign current XSD path in case of a match & break.
934
962
  validations[xml_file_path] = xsd_file_path
935
963
  break
@@ -941,7 +969,7 @@ class XmlValidator:
941
969
  raise ValueError(f"Unsupported search strategy: {search_by}.")
942
970
  # If no match has been found.
943
971
  if not validations[xml_file_path]:
944
- logger.info(f"No valid XSD found for {xml_file_path}.")
972
+ logger.info(f"\t\tNo valid XSD found for {xml_file_path}.")
945
973
  validations[xml_file_path] = FileNotFoundError(
946
974
  f'No matching XSD found for: {xml_file_path.stem}.'
947
975
  )
@@ -1238,7 +1266,7 @@ class XmlValidator:
1238
1266
  """
1239
1267
  # Log informative.
1240
1268
  logger.info(
1241
- f"Validating '{xml_file_path.stem}'.", also_console=True
1269
+ f"Validating '{xml_file_path.name}", also_console=True
1242
1270
  )
1243
1271
  # Check upstream XSD matching led to an err pertaining to the XML.
1244
1272
  if isinstance(xsd_file_path, BaseException):
@@ -1256,7 +1284,7 @@ class XmlValidator:
1256
1284
  )
1257
1285
  if not sanity_check_result.success:
1258
1286
  # Abort validation if one or more sanity checks failed.
1259
- logger.warn("File(s) failed basic sanity check.")
1287
+ # logger.warn("File(s) failed basic sanity check.")
1260
1288
  return False, sanity_check_result.error
1261
1289
  # Ensure a valid schema is loaded.
1262
1290
  loading_result = self._ensure_schema(
@@ -1432,7 +1460,7 @@ class XmlValidator:
1432
1460
  write_to_csv: Optional[bool] = True,
1433
1461
  timestamped: Optional[bool] = True,
1434
1462
  reset_errors: bool = True,
1435
- fail_on_errors: Optional[bool] = False
1463
+ fail_on_errors: Optional[bool] = None
1436
1464
  ) -> Tuple[
1437
1465
  List[ Dict[str, Any] ],
1438
1466
  str | None
@@ -1595,6 +1623,12 @@ class XmlValidator:
1595
1623
  # Reset attributes, if requested.
1596
1624
  if reset_errors:
1597
1625
  self.validator_results.reset()
1626
+ # Determine the validation strictness.
1627
+ fail_on_errors = (
1628
+ fail_on_errors \
1629
+ if fail_on_errors is not None \
1630
+ else self.fail_on_errors
1631
+ )
1598
1632
  # Determine and resolve/normalize the XML file path(s).
1599
1633
  xml_file_paths, is_single_xml_file = (
1600
1634
  self.validator_utils.get_file_paths(
@@ -55,6 +55,6 @@ try:
55
55
  __version__ = version("robotframework-xmlvalidator")
56
56
  except PackageNotFoundError:
57
57
  # Fall back when package not installed (default version for development).
58
- __version__ = "1.0.1"
58
+ __version__ = "2.0.0"
59
59
  import warnings
60
60
  warnings.warn("Package metadata not found, using fallback version.")
@@ -75,7 +75,7 @@ class ValidatorResultRecorder:
75
75
  and export validation results.
76
76
  """
77
77
 
78
- __version__ = '1.0.1'
78
+ __version__ = '2.0.0'
79
79
 
80
80
  errors_by_file: List[Dict[str, Any]] = field(default_factory=list)
81
81
  validation_summary: Dict[str, List[str]] = field(
@@ -331,7 +331,7 @@ class ValidatorResultRecorder:
331
331
  try:
332
332
  df.to_csv(output_csv_path, index=False)
333
333
  logger.info(
334
- f"Validation errors exported to '{output_csv_path}'.",
334
+ f"Validation errors exported to: \n\t'{output_csv_path}'.",
335
335
  also_console=True
336
336
  )
337
337
  except IOError as e:
@@ -43,7 +43,6 @@ from pathlib import Path
43
43
  from typing import List, Optional, Tuple, Union, TYPE_CHECKING
44
44
  # Third party library imports.
45
45
  from lxml import etree
46
- from robot.api import logger
47
46
  # Local application imports.
48
47
  from .xml_validator_results import ValidatorResult
49
48
  if TYPE_CHECKING:
@@ -67,7 +66,7 @@ class ValidatorUtils:
67
66
  All methods are static and the class maintains no internal state.
68
67
  """
69
68
 
70
- __version__ = '1.0.1'
69
+ __version__ = '2.0.0'
71
70
 
72
71
  @staticmethod
73
72
  def _resolve_path(path: str | Path) -> Path:
@@ -472,9 +471,9 @@ class ValidatorUtils:
472
471
  if isinstance(value, tuple):
473
472
  value = f"Line {value[0]}, Column {value[1]}."
474
473
  error_details[facet] = value
475
- logger.warn(
476
- f"Facet '{facet}' is not an attribute of error type'{type(e).__name__}'."
477
- )
474
+ # logger.warn(
475
+ # f"Facet '{facet}' is not an attribute of error type'{type(e).__name__}'."
476
+ # )
478
477
  # Add the error type to the error details
479
478
  error_details['Error type'] = type(e).__name__
480
479
  # Append the error to the return list.