You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+80-46
Original file line number
Diff line number
Diff line change
@@ -26,6 +26,10 @@
26
26
-[Using the library](#using-the-library)
27
27
-[Keyword overview](#keyword-overview)
28
28
-[Error collection](#error-collection)
29
+
-[XSD Schema violations.](#xsd-schema-violations)
30
+
-[Malformed XML](#malformed-xml)
31
+
-[File-level issues](#file-level-issues)
32
+
-[Final note on error collection](#final-note-on-error-collection)
29
33
-[Keyword documentation](#keyword-documentation)
30
34
-[Keyword example usage](#keyword-example-usage)
31
35
-[A few basic examples](#a-few-basic-examples)
@@ -205,76 +209,106 @@ That is, when it encounters an error in a file, it does not fail. Rather, it col
205
209
206
210
In that fashion the keyword works through the entire set of files.
207
211
208
-
When having finished checking the last file, 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.
212
+
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.
209
213
210
-
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, then 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.
214
+
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.
211
215
212
216
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).
213
217
214
218
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.
215
219
216
-
See for more details the [keyword documentation](https://michaelhallik.github.io/robotframework-xmlvalidator/XmlValidator.html).
220
+
For more details, please see the [keyword documentation](https://michaelhallik.github.io/robotframework-xmlvalidator/XmlValidator.html).
217
221
218
222
### Error collection
219
223
220
-
Errors that are collected and returned can be categorized as follows:
224
+
Errors that are collected and reported can be categorized as follows:
221
225
222
-
1. XSD Schema violations.
226
+
####XSD Schema violations.
223
227
224
-
The following types of XSD schema violations are detected during validation:
228
+
- Missing or extra elements that violate cardinality rules, e.g.:
229
+
- Verifies that all mandatory elements (minOccurs > 0) are present in the XML.
230
+
- Ensures that optional elements (minOccurs = 0) do not exceed their maximum allowed occurrences (maxOccurs).
225
231
226
-
1. Detects missing or extra elements that violate cardinality rules, e.g.:
227
-
- Verifies that all mandatory elements (minOccurs > 0) are present in the XML.
228
-
- Ensures that optional elements (minOccurs = 0) do not exceed their maximum allowed occurrences (maxOccurs).
232
+
- Sequence and order violations:
233
+
- Validates the order of child elements within a parent element if the schema specifies a sequence model (`<xsd:sequence>`).
234
+
- Detects elements that are out of order or missing in a sequence.
229
235
230
-
2. Sequence and Order Violations:
231
-
- Validates the order of child elements within a parent element if the schema specifies a sequence model (`<xsd:sequence>`).
232
-
- Detects elements that are out of order or missing in a sequence.
236
+
- Datatype violations:
237
+
- Ensures that element and attribute values conform to their specified datatypes (e.g., xs:string, xs:integer, xs:dateTime).
238
+
- Identifies invalid formats, such as incorrect date or time formats for xs:date and xs:dateTime.
233
239
234
-
3. Datatype Violations:
235
-
- Ensures that element and attribute values conform to their specified datatypes (e.g., xs:string, xs:integer, xs:dateTime).
236
-
- Identifies invalid formats, such as incorrect date or time formats for xs:date and xs:dateTime.
240
+
- Pattern and enumeration violations:
241
+
- Checks that values conform to patterns defined using `<xsd:pattern>`.
242
+
- Ensures that values fall within allowed enumerations specified in the schema.
237
243
238
-
4. Pattern and Enumeration Violations:
239
-
- Checks that values conform to patterns defined using `<xsd:pattern>`.
240
-
- Ensures that values fall within allowed enumerations specified in the schema.
244
+
- Attribute validation:
245
+
- Verifies that required attributes are present.
246
+
- Ensures that attribute values adhere to their declared datatypes and constraints.
241
247
242
-
5. Attribute Validation:
243
-
- Verifies that required attributes are present.
244
-
- Ensures that attribute values adhere to their declared datatypes and constraints.
248
+
- Namespace compliance:
249
+
- Validates that elements and attributes belong to the correct namespaces as defined in the schema.
250
+
- Detects namespace mismatches or missing namespace declarations.
245
251
246
-
6. Namespace Compliance:
247
-
- Validates that elements and attributes belong to the correct namespaces as defined in the schema.
248
-
- Detects namespace mismatches or missing namespace declarations.
252
+
- Group model violations:
253
+
- Validates conformance with `<xsd:choice>` and `<xsd:all>` group models, ensuring correct usage of child elements as per the schema.
249
254
250
-
7. Group Model Violations:
251
-
- Validates conformance with `<xsd:choice>` and `<xsd:all>` group models, ensuring correct usage of child elements as per the schema.
255
+
- Referential constraints:
256
+
- Checks for violations in `<xsd:key>`, `<xsd:keyref>`, and `<xsd:unique>` constraints.
252
257
253
-
8. Referential Constraints:
254
-
- Checks for violations in `<xsd:key>`, `<xsd:keyref>`, and `<xsd:unique>` constraints.
258
+
- Document structure and completeness:
259
+
- Ensures that the XML document adheres to the hierarchical structure defined by the schema.
260
+
- Detects incomplete or improperly nested elements.
255
261
256
-
9. Document Structure and Completeness:
257
-
- Ensures that the XML document adheres to the hierarchical structure defined by the schema.
258
-
- Detects incomplete or improperly nested elements.
262
+
- General schema violations:
263
+
- Detects schema-level issues, such as invalid imports or includes, during schema compilation if they affect validation.
259
264
260
-
10. General Schema Violations:
261
-
- Detects schema-level issues, such as invalid imports or includes, during schema compilation if they affect validation.
265
+
#### Malformed XML
262
266
263
-
2. Errors following from malformed XML and/or XSD files.
267
+
Malformed XML errors arise from issues that prevent the XML file from being parsed at all, before schema validation can even occur. These errors typically reflect syntactic problems in the structure or encoding of the XML content.
264
268
265
-
Checks whether handling of the involved XML file (e.g. during dynamic schema matching) resulted in an error. For instance because a file:
266
-
- does not exist (i.e. could not be found at the spefified location)
267
-
- is empty
268
-
- is not of the correct file type (.xml, .xsd)
269
-
- is not well-formed (syntactycally correct)
270
-
271
-
Any such error does not lead to a failing test, but is collected and reported.
269
+
Typical cases include:
272
270
273
-
However, when, at the end of a test run one or more errors have been collected, the test will be marked as 'FAILED'.
271
+
- Mismatched tags
272
+
- Opening and closing tags do not match.
273
+
- Example: `<Title>My Book</title>`
274
+
275
+
- Unclosed elements
276
+
- Elements are left unclosed or self-closing syntax is incorrect.
277
+
- Example: `<Price>12.99`
278
+
279
+
- Premature end-of-file
280
+
- The file ends abruptly before all tags are closed, often due to truncation or corruption.
281
+
- Example: `<Product><ID>123`
282
+
283
+
- Invalid characters or encoding
284
+
- The XML includes characters that are not valid in the declared encoding or in XML itself.
285
+
- Example: Control characters or non-UTF-8 bytes.
286
+
287
+
- Misused namespaces
288
+
- Prefixes declared but not bound, or invalid namespace URIs used.
289
+
290
+
- Declaration errors
291
+
- Malformed or duplicate `<?xml ... ?>` declarations.
292
+
293
+
#### File-level issues
294
+
295
+
General errors that do not pertain to syntax or schema issues:
| Missing File | The specified XML file could not be found |
300
+
| Empty File | The file exists but is completely empty |
301
+
| Wrong Format | The file is not `.xml` or `.xsd`|
302
+
303
+
#### Final note on error collection
304
+
305
+
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
306
+
307
+
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`.
274
308
275
309
### Keyword documentation
276
310
277
-
See the [keyword documention](https://michaelhallik.github.io/robotframework-xmlvalidator/XmlValidator.html).
311
+
See the [keyword documentation](https://michaelhallik.github.io/robotframework-xmlvalidator/XmlValidator.html).
278
312
279
313
The keyword documentation provides detailed descriptions of all functionalities, features and the various ways in which the library and its keywords can be employed.
280
314
@@ -435,7 +469,7 @@ These are the facets (or attributes) that can be collected and reported for each
435
469
|`severity`| The severity level of the error (not always present). |
436
470
| `args` | The arguments passed to the error message formatting.
437
471
438
-
Use the `error_facets`arg to set which error details to collect.
472
+
Use the `error_facets`argument to set which error details to collect.
439
473
440
474
For each error that is encountered, the selected error facet(s) will be collected and reported.
441
475
@@ -445,7 +479,7 @@ You can customize which error facet(s) should be collected, by passing a list of
445
479
446
480
Error facets passed during library initialization will be overruled by error facets that are passed at the test case level, when calling the `Validate Xml Files` keyword.
447
481
448
-
The values you can pass through the `error_facets` argument are based on the attributes of the error objects as returned by the XMLSchema.iter_errors() method, that is provided by the xmlschema library and the the xmlvalidator library leverages. Said method yields instances of xmlschema.validators.exceptions.XMLSchemaValidationError (or its subclasses), each representing a specific validation issue encountered in an XML file. These error objects expose various attributes that describe the nature, location, and cause of the problem.
482
+
The values you can pass through the `error_facets` argument are based on the attributes of the error objects as returned by the XMLSchema.iter_errors() method, that is provided by the xmlschema library and the xmlvalidator library leverages. Said method yields instances of xmlschema.validators.exceptions.XMLSchemaValidationError (or its subclasses), each representing a specific validation issue encountered in an XML file. These error objects expose various attributes that describe the nature, location, and cause of the problem.
449
483
450
484
The table lists the most commonly available attributes, though additional fields may be available depending on the type of validation error.
451
485
@@ -507,7 +541,7 @@ poetry install
507
541
poetry shell
508
542
```
509
543
510
-
Or, if you use a different virt env, activate that.
544
+
Or, if you use a different virt environment, activate that.
0 commit comments