Validating against schema & BREX
A data module passes through two separate checks before it is official. First you
check that the file is correct XML and matches its S1000D schema. Then you
check that the content obeys the project's business rules, recorded in a
BREX data module. The
s1kd-tools toolchain gives you one
command for each check: s1kd-validate and s1kd-brexcheck.
s1kd-validate answers "Is this a well-formed S1000D file?" s1kd-brexcheck
answers "Does this file follow my project's rules?" A data module can pass the
first and fail the second. You usually run both.
The commands and the data module filename on this page are examples. Tool names
and option flags are verified against the s1kd-tools documentation (see
Sources). The data module code DMC-MYPRJ-A-00-00-00-00A-040A-D_000-03_EN-CA
is a sample, not a real product.
Step 1 — Validate against the schema
s1kd-validate checks whether a CSDB object is valid XML and whether it is valid
against its own S1000D schema. The schema reference lives inside the data module,
so you do not normally name a schema on the command line.
# Example only — illustrative data module filename.
s1kd-validate DMC-MYPRJ-A-00-00-00-00A-040A-D_000-03_EN-CA.XML
If the file is clean, the tool prints nothing and exits with status 0. If the
file is malformed or breaks its schema, the tool reports the problem and exits
with a non-zero status. A few useful options:
| Option | What it does |
|---|---|
-v, --verbose | Report success as well as failure |
-q, --quiet | Print nothing; use the exit status only |
-f, --filenames | List the names of invalid files only |
-x, --xml | Write the report as XML |
-T, --summary | Print validation statistics |
-s, --schema <path> | Override the object's default schema |
The exit status lets you wire s1kd-validate into a script or a CI pipeline:
| Exit status | Meaning |
|---|---|
0 | No errors found |
1 | One or more objects are malformed or invalid |
2 | Schema cache ran out of memory |
3 | A specified schema could not be read |
s1kd-validate accepts many objects on one command line, and the -q flag
makes it silent except for the exit status. That pair is handy for a pre-commit
hook: validate every data module, and fail the commit if any object is invalid.
Step 2 — Check against the BREX
A file can be valid XML and still break a project rule — for example, by using an
information code the project has banned, or by leaving out an element the project
requires. The schema cannot catch this, because the rule is specific to the
project, not to S1000D as a whole. That is the job of s1kd-brexcheck.
s1kd-brexcheck validates CSDB objects using the context, SNS, and
notation rules of one or more BREX data modules. By default it finds the BREX
each object references and checks the object against it.
# Example only — illustrative data module filename.
s1kd-brexcheck DMC-MYPRJ-A-00-00-00-00A-040A-D_000-03_EN-CA.XML
Common options:
| Option | What it does |
|---|---|
-b, --brex <brex> | Check against a named BREX; repeat for several |
-B, --default-brex | Check against the built-in S1000D default BREX only |
-S, --sns | Check Standard Numbering System rules |
-n, --notations | Check notation rules |
-c, --values | Check the object values named in context rules |
-l, --layered | Follow layered (chained) BREX references |
-v, --verbose | Print explicit test results |
-x, --xml | Write the report as XML |
The exit status reports what happened:
| Exit status | Meaning |
|---|---|
0 | No BREX errors found |
1 | Some objects had BREX errors |
2 | An object could not be read |
3 | A referenced BREX module was not found |
4 | An unsupported XPath version was requested |
5 | The memory limit was exceeded |
s1kd-brexcheck evaluates BREX context rules as XPath. By default it supports
XPath 1.0, with partial support for EXSLT functions. Write project rules with
this in mind.
What a BREX failure means
A BREX failure does not mean the file is broken XML. It means the content breaks a rule the project chose to enforce. The data module is still a valid S1000D file; it is simply not allowed under this project's business rules.
For each violation, s1kd-brexcheck reports three things:
- The
objectUsemessage — the plain-language note the BREX author wrote to explain the rule. This tells you why the rule exists. - The line number in the data module where the rule was broken.
- A representation of the invalid XML tree — the part of the content that triggered the failure.
Together these point you straight to the offending element and tell you the project's intent. To fix a BREX failure you change the content so it obeys the rule — for example, remove a forbidden element, add a required attribute, or use a permitted value. You do not change the schema.
The objectUse text is the most useful part of the report. It is the rule
author speaking directly to you. If a check keeps failing, the message usually
explains the project decision behind the rule — see
Business rules & BREX for how those
decisions are recorded.
Putting both checks together
A typical "make it official" sequence runs the two tools in order. Schema first, because there is no point checking business rules on a file that is not even valid XML; rules second, because that is where project-specific problems show up.
# Example only — illustrative data module filename.
s1kd-validate DMC-MYPRJ-A-00-00-00-00A-040A-D_000-03_EN-CA.XML
s1kd-brexcheck DMC-MYPRJ-A-00-00-00-00A-040A-D_000-03_EN-CA.XML
| Tool | Question it answers | A failure means |
|---|---|---|
s1kd-validate | Is the file valid XML and valid S1000D? | Wrong structure — fix syntax or schema conformance |
s1kd-brexcheck | Does the file follow the project's rules? | Wrong content choice — fix to match the BREX |
Summary
- Validate every data module twice: against its schema, then against its BREX.
s1kd-validatechecks XML well-formedness and S1000D schema conformance.s1kd-brexcheckchecks content against the context, SNS, and notation rules of a BREX data module.- A BREX failure means the file is valid S1000D but breaks a project rule;
the report gives the
objectUsemessage, the line number, and the offending XML. - Both tools use exit status, so they fit cleanly into a script or CI pipeline.