Skip to main content

validate_bes_xml

A python module for validating BigFix XML files and content.

Validates .bes and .ojo files against the official BigFix XML schemas (bundled with the module) and reports what is wrong and where when a file does not validate. Useful locally and as a CI check for repositories of BigFix content.

How it works

For each XML file, the validator:

  1. Parses the file and reports XML syntax errors, if any.
  2. Determines which schema to use, in this order:
    • .ojo in the file name -> BESOJO.xsd
    • .BESDomain in the file name (any case) -> BESDomain.xsd
    • an attribute on the root tag referencing an .xsd file (e.g. xsi:noNamespaceSchemaLocation="BES.xsd")
    • the name of the root tag itself (e.g. <BES> -> BES.xsd)
  3. Validates the file against that schema and prints the line number and reason for every schema violation found.

Bundled schemas:

  • BES.xsd - Fixlets, Tasks, Analyses, Baselines, Computer Groups, etc.
  • BESAPI.xsd - BigFix REST API XML
  • BESOJO.xsd - Wizards / Dashboards (.ojo files)
  • BESDomain.xsd - Domain content

Additional .xsd files placed in the current working directory (or a schemas subfolder of it) are picked up automatically. A schema is matched by its exact file name, and the bundled copy is always used over another file with the same name. An .xsd that cannot be read or parsed is skipped with a warning on stderr.

Requirements

Installation

pip install validate-bes-xml

Or from a clone of this repository:

pip install .

Usage

Command line

Validate all .bes and .ojo files in the current directory and its subfolders (excluding .git):

python -m validate_bes_xml

The exit code is the number of files that failed validation, so 0 means everything validated. This makes it easy to use as a CI check:

# example GitHub Actions step
- name: Validate BES XML
  run: |
    pip install validate-bes-xml
    python -m validate_bes_xml

Example output for an invalid file:

Schema Validation Error in: ./example.bes
  validated against schema: .../validate_bes_xml/schemas/BES.xsd
  Line 2: Element 'BES': Missing child element(s). Expected is one of ( Fixlet, Task, Analysis, SingleAction, SourcedFixletAction, MultipleActionGroup, Baseline, ComputerGroup, CustomSite, ActionSite ).
2 errors found in 71 xml files

Python

import validate_bes_xml

# validate a single file, returns True or False:
validate_bes_xml.validate_xml("example.bes")

# validate all .bes and .ojo files in a folder tree,
# returns the number of files that failed validation:
validate_bes_xml.validate_all_files("path/to/content")

# customize which file extensions are scanned:
validate_bes_xml.validate_all_files(".", file_extensions=(".bes",))

To validate XML that is not in a file on disk, or to get the errors back instead of printed, use validate_bes(). It never prints, and returns a ValidationResult that is truthy when valid:

import validate_bes_xml

result = validate_bes_xml.validate_bes(raw_bytes, filename="example.bes")
if not result:
    print("failed against", result.schema)
    for line, message in result.errors:
        print(f"Line {line}: {message}")

validate_bes() accepts:

  • a file path, as a str or pathlib.Path
  • XML text, as a str that starts with < (a leading BOM is ignored)
  • bytes, bytearray, or memoryview (the XML encoding declaration is used)
  • a binary or text file-like object
  • a parsed lxml.etree ElementTree or Element

Use xml= or path= instead of the first argument to skip guessing whether a str is XML text or a path. Pass filename= so in-memory XML gets the same .ojo / .BESDomain schema rules as a file. It defaults to the path, or to the .name of an open file.

ValidationResult fields:

  • valid: True or False
  • schema: path of the schema that was used, or None when the XML did not parse or no bundled schema matched
  • errors: list of (line, message) tuples; line is None when unknown
  • status: a validate_bes_xml.Status, one of the values below
  • inferred_schema: the schema file name that was looked up, such as "BES.xsd", set whenever the XML parsed (even if no schema matched), else None
status Meaning
"valid" parsed, and passed the schema
"invalid" parsed, and failed the schema
"syntax_error" not well-formed XML
"no_schema" parsed, but no schema matched inferred_schema
"error" anything else: unreadable file, no root element, or a schema that failed to compile

Status members compare equal to their string values, so result.status == "no_schema" and result.status is Status.NO_SCHEMA both work. Only a result with status "valid" is truthy: a "no_schema" result is falsy, as before. Test the result, not result.status, since every Status member is a non-empty string and so is itself truthy.

To treat "no schema applies" as validity unknown instead of invalid, check status, not whether line is None:

from validate_bes_xml import Status, validate_bes

result = validate_bes(raw_bytes)
if result.status is Status.NO_SCHEMA:
    print("no schema for", result.inferred_schema)
elif not result:
    print(result.status, result.errors)

status must agree with valid: ValidationResult(valid=True, status="invalid") raises ValueError. So to change valid with dataclasses.replace(), also pass status=None to derive it again, for example dataclasses.replace(result, valid=True, status=None). Setting result.valid directly does not update status.

Each .xsd is compiled once per process and reused.

validate_xml(path, verbose=False) validates a file without printing.

Development

Clone the repository, then install the requirements:

pip install -r requirements.txt
pip install pytest

Run the tests from the root of the repository:

pytest -v

The test examples live in tests/examples: files in good must validate, files in bad must not.

License

MIT

Metadata

Release files for validate-bes-xml 2.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for validate-bes-xml 2.3.0
File Size Uploaded Provenance Actions
validate_bes_xml-2.3.0.tar.gz 42.4 kB Without provenance Details for validate_bes_xml-2.3.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for validate-bes-xml 2.3.0
File Interpreter ABI Platform Actions
validate_bes_xml-2.3.0-py3-none-any.whl Python 3 none any Details for validate_bes_xml-2.3.0-py3-none-any.whl

Total release size: 66.8 kB

Release files / validate_bes_xml-2.3.0.tar.gz

Download URL validate_bes_xml-2.3.0.tar.gz
Size 42.4 kB
Tags Source
SHA-256 checksum
How to use checksums
04b34be08c595d1c9702de3692ddcc11ed72b0786dff26ecae0d44f162d24ffd
BLAKE2b-256 checksum
How to use checksums
5040338ea3220b2dfb4055cab814739907f774210d5d6d6aba4bace6e0473066
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / validate_bes_xml-2.3.0-py3-none-any.whl

Download URL validate_bes_xml-2.3.0-py3-none-any.whl
Size 24.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
380295dcc8b7401a27a571f01dfea413fc5248b604e58c7b4e4143bd712add65
BLAKE2b-256 checksum
How to use checksums
739caa0fa7ec0cf40a77e7eff83ff0fc4546bfa0703ba08af22ab613e928f9a9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Security for validate-bes-xml 2.3.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page