xmlgenerator 0.2.4

Generate XML instances from an XML Schema (XSD)
docs.rs failed to build xmlgenerator-0.2.4
Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.

XML Generator

Rust XML GitHub Pytest GitHub Actions Test Rust Coffee License: MIT No AI

This crate is the primary Rust crate in the repo. It uses the xsd-parser crate to parse the input XSD into a SchemaData object. Next, the XSD data is validated using the xsd-validator. A Generator object is created for managing the generation of randomised strings. These objects are then combined into an Xsd object, this object sorts the schema content into a new structure primed for generating a new XML instance. After this, the new XML is generated.

Randomised Generation

The crate uses the rand-regex crate to generate regex strings based on the input pattern. This process is random, and therefore non-deterministic. For more complicated regex patterns, this can fail, but repeated attempts may yield a suitable output.

Example Usage

The following is an example of a simplified program which reads a list of filepaths from command-line arguments and generates example XML output strings for each valid XSD.

use std::path::PathBuf;
use std::str::FromStr;
use xmlgenerator:XmlGenerator;

fn main() {
    let generator =XmlGenerator::new();

    let path = PathBuf::from_str("input.xsd").unwrap();

    // Unseeded
    let output = match generator.validate(&path, None) {
        Ok(out) => out,
        Err(e) => {
            eprintln!("Error generating XML: {}", e);
            return;
        }
    };

    println!("Output XML generated!");

    println!("{}", output);
}

NOTE: Only a single XmlGenerator` should be created. Multiple instances of this class cause undefined behaviour.