Skip to content

Commit 3a68ef6

Browse files
Michael HallikMichael Hallik
Michael Hallik
authored and
Michael Hallik
committed
Textual improvment of the README.
1 parent bbef504 commit 3a68ef6

File tree

1 file changed

+80
-46
lines changed

1 file changed

+80
-46
lines changed

README.md

+80-46
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@
2626
- [Using the library](#using-the-library)
2727
- [Keyword overview](#keyword-overview)
2828
- [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)
2933
- [Keyword documentation](#keyword-documentation)
3034
- [Keyword example usage](#keyword-example-usage)
3135
- [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
205209

206210
In that fashion the keyword works through the entire set of files.
207211

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.
209213

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.
211215

212216
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).
213217

214218
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.
215219

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).
217221

218222
### Error collection
219223

220-
Errors that are collected and returned can be categorized as follows:
224+
Errors that are collected and reported can be categorized as follows:
221225

222-
1. XSD Schema violations.
226+
#### XSD Schema violations.
223227

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).
225231

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.
229235

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.
233239

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.
237243

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.
241247

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.
245251

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.
249254

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.
252257

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.
255261

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.
259264

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
262266

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.
264268

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:
272270

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:
296+
297+
| Error Type | Description |
298+
|--------------|-------------------------------------------|
299+
| 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`.
274308

275309
### Keyword documentation
276310

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).
278312

279313
The keyword documentation provides detailed descriptions of all functionalities, features and the various ways in which the library and its keywords can be employed.
280314

@@ -435,7 +469,7 @@ These are the facets (or attributes) that can be collected and reported for each
435469
| `severity` | The severity level of the error (not always present). |
436470
| `args` | The arguments passed to the error message formatting.
437471

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.
439473

440474
For each error that is encountered, the selected error facet(s) will be collected and reported.
441475

@@ -445,7 +479,7 @@ You can customize which error facet(s) should be collected, by passing a list of
445479

446480
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.
447481

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.
449483

450484
The table lists the most commonly available attributes, though additional fields may be available depending on the type of validation error.
451485

@@ -507,7 +541,7 @@ poetry install
507541
poetry shell
508542
```
509543

510-
Or, if you use a different virt env, activate that.
544+
Or, if you use a different virt environment, activate that.
511545

512546
### Running tests
513547

0 commit comments

Comments
 (0)