Ootempl.Validator (ootempl v0.3.0)
Provides validation functions for .docx files.
This module validates .docx file structure, ensuring files are valid ZIP archives, contain required files, and have well-formed XML content.
Required .docx Files
All valid .docx files must contain:
word/document.xml- Primary document content[Content_Types].xml- MIME type definitions_rels/.rels- Package-level relationships
Validation Workflow
Use validate_docx/1 to run all validation checks:
case Ootempl.Validator.validate_docx("template.docx") do
:ok -> # File is valid
{:error, exception} -> # File is invalid, exception has details
endOr use individual validation functions for specific checks:
validate_archive/1- Check if file is a valid ZIPvalidate_structure/1- Verify required files existvalidate_xml/1- Check if XML string is well-formed
Summary
Functions
Runs all validation checks on a .docx file.
Functions
@spec validate_docx(Path.t()) :: :ok | {:error, Ootempl.ValidationError.t() | Ootempl.InvalidArchiveError.t() | Ootempl.MissingFileError.t() | Ootempl.MalformedXMLError.t()}
Runs all validation checks on a .docx file.
Performs the following validations in order:
- File exists and is a regular file
- File is a valid ZIP archive
- All required files are present
- The main document XML is well-formed
Returns :ok if all checks pass, or {:error, exception} with a specific
error type indicating the first validation failure.
Examples
iex> Ootempl.Validator.validate_docx("template.docx")
:ok
iex> Ootempl.Validator.validate_docx("nonexistent.docx")
{:error, %Ootempl.ValidationError{reason: :file_not_found}}
iex> Ootempl.Validator.validate_docx("corrupt.docx")
{:error, %Ootempl.InvalidArchiveError{}}