tomato·bazeldocs v0 · latest
Docs/Reference/Modules/rules_xsd

rules_xsd

Bazel rules for XSD: offline schema validation + XSD→RDF/OWL vocabulary generation.

Latest0.0.1
Versions1
CategoryBazel rules
MaintainersMatt Marshall
Registryhttps://registry.tbzl.dev/modules/rules_xsd/
Sourcegithub.com/tomato-bazel/rules_xsd
MODULE.bazelstarlark
bazel_dep(name = "rules_xsd", version = "0.0.1")

View source & releases on GitHub ↗

Bazel rules for XSD: offline schema validation + XSD→RDF/OWL vocabulary generation (the rules_xsd seed lifted from uslm).

Status: v0.0.1 — scaffold

No public surface yet. See CHANGELOG.md for what has shipped.

Install

.bazelrc:

common --registry=https://registry.fastverk.com/
common --registry=https://bcr.bazel.build/

MODULE.bazel:

bazel_dep(name = "rules_xsd", version = "0.0.1")

Usage#

Real usage, taken from the module’s examples/.

examples/BUILD.bazel

load("//xsd:defs.bzl", "xsd_schema", "xsd_to_vocab", "xsd_validate_test")

package(default_visibility = ["//visibility:public"])

# A two-schema closure: person.xsd imports common.xsd by namespace. The import's
# schemaLocation is a remote URL that is never fetched — xsd_validate resolves it
# from this local closure (matched on targetNamespace), so the gate is offline.

xsd_schema(
    name = "common",
    srcs = ["common.xsd"],
)

xsd_schema(
    name = "person",
    srcs = ["person.xsd"],
    deps = [":common"],
)

# Gate: the instance validates against the person schema + its closure.
xsd_validate_test(
    name = "person_valid",
    schema = ":person",
    xml = "person.xml",
)

# XSD → RDF/OWL: generate a Turtle vocabulary (person → owl:Class, id → property).
xsd_to_vocab(
    name = "person_vocab",
    namespace = "https://example.org/person#",
    schema = ":person",
)

Rules & providers#

Generated with Stardoc from the module's .bzl sources.

from docs/defs.md

User-facing XSD rules (the rules_xsd seed).

Two rules, deliberately shaped like rules_rdf’s rdf_dataset + rdf_validate_test so the whole package lifts into a standalone rules_xsd ruleset once the shape settles (legislative-kg §11):

  • xsd_schema(name, srcs, deps) — declare an XSD plus the schemas it imports (as other xsd_schema targets). Produces XsdInfo carrying the transitive import closure, the XSD analog of an rdf_dataset closure.

  • xsd_validate_test(name, schema, xml) — assert an XML instance validates against an XsdInfo’s schema (resolving every <xsd:import> from the local closure, never the network). The first correct-by-construction gate.

load("//xsd:defs.bzl", "xsd_schema", "xsd_validate_test")

xsd_schema(name = "xml_ns", srcs = ["@uslm_schema//:xml.xsd"])
xsd_schema(name = "uslm",   srcs = ["@uslm_schema//:USLM-1.0.15.xsd"], deps = [":xml_ns", ...])

xsd_validate_test(name = "slice_valid", schema = ":uslm", xml = "//data:usc_t26_slice.xml")

Next step (the owl:imports-strict-manifest analog): an aspect that parses each schema’s <xsd:import namespace=…> and fails unless every imported namespace is covered by a declared dep’s targetNamespace — a closure-completeness gate. For the first cut, deps are explicit and the validator fails loudly if a needed namespace is absent from the closure.

xsd_schema

load("@rules_xsd//xsd:defs.bzl", "xsd_schema")

xsd_schema(name, deps, srcs, root)

Declare an XSD schema + its transitive import closure.

ATTRIBUTES

NameDescriptionTypeMandatoryDefault
nameA unique name for this target.Namerequired
depsImported schemas (other xsd_schema targets); their closures fold into this one’s transitive_files.List of labelsoptional[]
srcsThis schema’s own .xsd file(s).List of labelsrequired
rootEntry-point schema to validate / generate against (defaults to srcs[0]).LabeloptionalNone

xsd_to_vocab

load("@rules_xsd//xsd:defs.bzl", "xsd_to_vocab")

xsd_to_vocab(name, namespace, schema)

Generate a Turtle RDF/OWL vocabulary from an XSD — the ‘XSD -> RDF, first instance’. Feed the output to jena_schemagen for typed views.

ATTRIBUTES

NameDescriptionTypeMandatoryDefault
nameA unique name for this target.Namerequired
namespaceOntology namespace IRI for the generated terms (defaults to the schema’s targetNamespace + ’#’).Stringoptional""
schemaThe xsd_schema whose root is translated to an RDF/OWL vocabulary.Labelrequired

xsd_validate_test

load("@rules_xsd//xsd:defs.bzl", "xsd_validate_test")

xsd_validate_test(name, schema, xml)

Assert an XML instance validates against an XSD closure (offline).

ATTRIBUTES

NameDescriptionTypeMandatoryDefault
nameA unique name for this target.Namerequired
schemaThe xsd_schema to validate against (its closure resolves imports).Labelrequired
xmlThe XML instance to validate.Labelrequired

from docs/providers.md

Providers for the generic XSD layer (the rules_xsd seed).

XsdInfo is the XSD analog of rules_rdf’s RdfDatasetInfo: a schema plus the transitive closure of the schemas it imports, so a validator (or, later, an XSD→emitter generator) sees the whole closure with no network access. An XSD is rarely standalone — USLM-1.0 imports XML, Dublin Core terms, and XHTML — so the closure is first-class, exactly as RDF graphs carry their owl:imports closure.

XsdInfo

load("@rules_xsd//xsd:providers.bzl", "XsdInfo")

XsdInfo(schema_root, transitive_files)

A declared XSD schema and its transitive import closure.

FIELDS

NameDescription
schema_rootFile: the entry-point .xsd to validate / generate against.
transitive_filesdepset[File]: schema_root plus the full import closure (this schema’s own srcs + every dep’s closure).

Conformance#

No gate findings. 10 contested atoms. See how gating works or the full report.

Contested atoms

Third-party modules where this module resolves a different version than others do. Not a violation of anything this module did — it is the actionable form of a registry-level convergence finding, and the sentence a maintainer can act on.

AtomResolved hereElsewhere
apple_support 1.24.2 2.2.0 ×1
bazel_skylib 1.8.2 1.9.0 ×2
gazelle 0.36.0 0.30.0 ×50.44.0 ×10.51.0 ×3
nlohmann_json 3.6.1 3.12.0.bcr.1 ×1
protobuf 33.4 34.0.bcr.1 ×2
rules_go 0.60.0 0.39.1 ×5
rules_jvm_external 6.7 6.8 ×4
rules_python 1.7.0 2.0.1 ×1
rules_swift 3.1.2 3.6.1 ×1
upb 0.0.0-20220923-a547704 0.0.0-20230516-61a97ef ×1

Dependencies#

rules_xsd in the registry graph — what it depends on (left) and what depends on it (right).

Depends on

platforms1.0.0bazel_skylib1.8.2rules_java8.15.2rules_jena0.3.2rules_shell0.6.1devstardoc0.7.2devrules_jsonschema0.2.0dev

Versions#

1 published version, newest first. Each resolves to an immutable, integrity-checked archive.

VersionIntegrity (sha256)Source archive
0.0.1 latest xvqoq60YXcIhNxlq… tag archive ↗

Changelog#

All notable changes to rules_xsd. The format is loosely Keep a Changelog — version headers mirror the published bazel-registry entries.

0.0.1 — scaffold

  • Initial scaffold via rels scaffold. No public API yet.

← All modules