Published 2025-09-18
A Dart package for validating XML files against XSD schemas. This package provides functionality to validate XML files in batch, generate validation reports, and ensure XML documents conform to specified schemas.

xmllint for full schema validation (if available on system)Add this package to your Dart project's pubspec.yaml file:
dependencies:
pkg_xml_validator: ^1.0.0 # Replace with the latest version
Then run:
dart pub get
xmllint installedxmllint is not available, the package falls back to basic XML structure validationbrew install libxml2apt-get install libxml2-utilschoco install libxml2import 'package:pkg_xml_validator/pkg_xml_validator.dart';
void main() async {
final validator = XmlValidator();
final bool isValid = await validator.validateXmlFiles(
fileCollectFolder: 'path/to/xml/files',
xsdPath: 'path/to/schema.xsd',
errorReportPath: 'path/to/save/error/report',
);
if (isValid) {
print('All XML files are valid!');
} else {
print('Some XML files failed validation. Check the error report.');
}
}
If you don't specify paths for XSD or error reports, the package will use these defaults:
assets/ directoryassets/ directoryimport 'package:pkg_xml_validator/pkg_xml_validator.dart';
void main() async {
final validator = XmlValidator();
// Using default paths for XSD and error reports
final bool isValid = await validator.validateXmlFiles(
fileCollectFolder: 'path/to/xml/files',
);
}
pkg_xml_validator/
├── lib/
│ ├── pkg_xml_validator.dart # Main library file
│ └── src/
│ └── services/
│ └── xml_validator.dart # Core validation implementation
├── assets/
│ ├── xml_files/ # Sample XML files
│ │ ├── order_conformation/ # Sample XML order confirmations
│ │ └── print/ # Sample XML print orders
│ └── xsd_files/ # XSD schema files
└── example/
└── pkg_xml_validator_example.dart # Usage example
When validation fails, the package generates a detailed error report showing:
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License - see the LICENSE file for details.
mockito and mocktail dependencies (did nothing).