xrust/validators/
mod.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33

pub mod dtd;

use crate::item::{Node, NodeType};
use crate::validators::dtd::validate_dtd;

#[derive(Clone)]
pub enum Schema{
    DTD
    //Will add the rest as they become available.
}

#[derive(Debug)]
pub enum ValidationError{
    DocumentError(String),
    SchemaError(String)
}


pub(crate) fn validate(doc: &impl Node, schema: Schema) -> Result<(), ValidationError>{
    match doc.node_type(){
        NodeType::Document => {
            match schema {
                Schema::DTD => {
                    validate_dtd(doc.clone())
                }
            }
        }
        _ => {
            Err(ValidationError::DocumentError("Node provided was not a document".to_string()))
        }
    }
}