Validate DocLang XML documents against XSD schema and Schematron rules.
pip install doclangdoclang validate my_document.dclg.xml## Inject DocLang namespace if document doesn't declare it:
doclang validate my_document.dclg.xml --allow-empty-namespace
# XSD validation only
doclang validate my_document.dclg.xml --xsd-only
# Schematron validation only
doclang validate my_document.dclg.xml --schematron-only
# JSON output
doclang validate my_document.dclg.xml --format json
# Quiet mode (exit code only)
doclang validate my_document.dclg.xml --quiet
# Show help
doclang --helpfrom doclang import validate, ValidationError
try:
validate("my_document.dclg.xml")
print("Validation OK (no exception)")
except ValidationError as exc:
print(exc) # human-readable summary
print(f"{exc.xsd_errors=}")
print(f"{exc.schematron_errors=}")Standard XML Schema Definition for structural validation:
- Document structure and element hierarchy
- Data types and attributes
- Element ordering
Additional business rules that XSD cannot express, using XSLT 3.0 and XPath 3.1:
<sch:pattern id="my-rule">
<sch:rule context="dl:element">
<sch:assert test="condition">Error message</sch:assert>
</sch:rule>
</sch:pattern>The validation uses XSLT 3.0 for modern XPath features.
In VS Code you can use Red Hat's XML extension and enable IDE-native XSD validation by adding the following to your settings.json (ℹ️ replacing the actual XSD path):
"xml.fileAssociations": [
{
"pattern": "**/*.dclg.xml",
"systemId": "file:///absolute/path/to/doclang.xsd",
}
],For this to work, the DocLang XML document must include the relevant namespace:
<doclang xmlns="https://www.doclang.ai/ns/v0">
<!-- ... -->
</doclang>Note that this approach does not cover Schematron validation rules.