schema_generator 0.2.0

This crate is a part of the ClimateForest project, which takes place between 01.03.2024–28.02.2027. It is funded by Interreg Aurora and supported by its contributors, including Metsäkeskus, Lapland University of Applied Sciences, Luke luonnonvarakeskus, Luleå Tekniska Universitet, Skoggstyrelsen, and SLU.
Documentation



// A struct
#[derive(Debug)]
pub struct XMLStruct {
    name: String,   // The name of the struct
    pub fields: Vec<XMLField>,  // Fields in the struct
}

// A field
#[derive(Debug, Clone)]
pub struct XMLField {
    pub name: String,   // The name of the field
    pub field_type: String,  // The type of the field  
}

fn create_structs(reader: &mut Reader<&[u8]>) -> HashMap<String, XMLStruct> {

    // Stack of structs being constructed
    let mut stack: Vec<XMLStruct> = Vec::new();

    // Finalized structs
    let mut structs: HashMap<String, XMLStruct> = HashMap::new(); 

    loop {
        match reader.read_event() {

            // Handle a start tag:
            Ok(Start(ref e)) => {
                // Create a new struct for this element
                // Push the struct onto the stack
                // If there's a parent struct, add this struct as a field to the parent struct
            },

            // Handle a self-closing tag:
            Ok(Empty(ref e)) => {
                // Create a new struct for this element
                // If there's a parent struct, add this struct as a field to the parent struct
            },

            // Handle an end tag:
            Ok(End(ref e)) => {
                // Pop the current struct from the stack
                // Update the finalized structs with the current struct
                // Merge fields if the struct already exists in the finalized collection of structs
            },

            // End of XML, exit the loop
            Ok(Eof) => break,

            // Handle parsing errors
            Err(e) => panic!("Error at position {}: {:?}", reader.buffer_position(), e),

            // Handle other events
            _ => (),
        }
    }

    structs
}