pkg_xml_validator version: 1.0.5

Published 2025-09-18

reinbeumer

sdk | dart
repository | svn
platform | generic
status | n/a
  • Readme
  • Changelog
  • Versions

XML Validator Package

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.

graph

Features

  • Comprehensive XML validation against XSD schema files
  • Dual validation strategy:
    • Primary: Uses xmllint for full schema validation (if available on system)
    • Fallback: Basic XML structure validation for well-formedness
  • Batch processing of multiple XML files
  • Detailed error reporting with formatted output
  • Flexible configuration with customizable paths for XML files, XSD schemas, and error reports

Installation

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

Prerequisites

  • For full XSD validation, the system should have xmllint installed
  • If xmllint is not available, the package falls back to basic XML structure validation

Installing xmllint

  • macOS: brew install libxml2
  • Ubuntu/Debian: apt-get install libxml2-utils
  • Windows: Install via Chocolatey: choco install libxml2

Usage

Basic Usage

import '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.');
  }
}

Using Default Paths

If you don't specify paths for XSD or error reports, the package will use these defaults:

  • XSD Schema: First .xsd file found in the assets/ directory
  • Error Report: Saved to the assets/ directory
import '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',
  );
}

Project Structure

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

Error Reporting

When validation fails, the package generates a detailed error report showing:

  • Number of files that failed validation
  • File paths of invalid XML documents
  • Specific error messages for each file
  • Timestamp of validation

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Changelog

1.0.5 - 2025-09-18

Changed

  • Removed mockito and mocktail dependencies (did nothing).

1.0.4 - 2025-09-16

Changed

  • Version bump from 1.0.3 to 1.0.4 (xml -> 6.6.1 (was 6.5.0)).

1.0.3 - 2025-09-04

Changed

  • Version bump from 1.0.2 to 1.0.3 (mockito -> 5.5.0 (was 5.5.1)).

1.0.2 - 2025-09-04

Changed

  • Version bump from 1.0.1 to 1.0.2 (mockito -> 5.5.1 (was 5.4.6)).

1.0.1 - 2025-07-23

Changed

  • Version bump from 1.0.0 to 1.0.1 (test -> 1.26.3 (was 1.26.2)).

1.0.0 - 2025-05-26

Changed

  • changed the return type.

0.0.6 - 2025-05-22

Changed

  • Version bump from 0.0.5 to 0.0.6 (lints -> 6.0.0 (was 5.1.1)).

0.0.5 - 2025-05-22

Changed

  • Version bump from 0.0.4 to 0.0.5 (lints -> 5.1.1 (was 6.0.0)).

0.0.4 - 2025-05-22

Changed

  • Version bump from 0.0.3 to 0.0.4 (test -> 1.26.2 (was 1.26.1)).

0.0.3 - 2025-05-21

Changed

  • Version bump from 0.0.2 to 0.0.3 (test -> 1.26.1 (was 1.24.0)).

0.0.2 - 2025-05-21

Changed

  • Version bump from 0.0.1 to 0.0.2 (lints -> 5.1.1 (was 5.0.0)).

0.0.1 - 2025-05-20

  • Initial version.

1.0.5

2025-09-18 download

1.0.3

2025-09-04 download

1.0.1

2025-07-23 download

1.0.0

2025-05-26 download

0.0.6

2025-05-22 download

0.0.3

2025-05-21 download

0.0.1

2025-05-20 download