xmlschemagenerator

github crates.io docs.rs build status

A collection of helper functions to read a given XML string or stream using quick_xml and generating a Struct (as String) that you can use in your Rust program to serialize or deserialize XML of the same format

You can add this dependency with:

toml [dependencies] xml_schema_generator = "0.2.1"

Example

How to implement the lib ```rust use quick_xml::reader::Reader;

use xml_schema_generator::{Element, into_struct};

let xml = "<a b=\"c\">d</a>";
let mut reader = Reader::from_str(xml);
let mut root = Element::new(String::from("root"), Vec::new());

into_struct(&mut reader, &mut root);

let rs_struct = root.to_serde_struct();
// save this result as a .rs file and use it to (de)serialize an XML document with serde

```

How to run the binary ```bash # parse input.xml and print struct to stdout $ cargo run -- input.xml

# parse input.xml and store struct to output.rs
$ cargo run -- input.xml output.rs

```

Contribution

Just create a well tested Pull Request in github

Implemented features

☑ parse UTF-8 xml file

☑ generate Rust struct

☑ detect optional attributes

☑ detect optional children

☑ add a binary to run this lib independently

Ideas (if needed or requested via github)

☐ properly parse namespaces and reflect them in the Rust Struct

☐ detect numeric and boolean fields

☐ improve the implementation of String, &str and [u8]

☐ improve performance

☐ generate XSD files

☐ support UTF-16

☐ suppport ISO2022JP

☐ parse multiple XML files into one result

License

Apache-2.0