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 34
|
//!
//! Example Usage of XSD Schema Validation
//!
use libxml::schemas::SchemaParserContext;
use libxml::schemas::SchemaValidationContext;
use libxml::parser::Parser;
fn main() {
let xml = Parser::default()
.parse_file("tests/resources/schema.xml")
.expect("Expected to be able to parse XML Document from file");
let mut xsdparser = SchemaParserContext::from_file("tests/resources/schema.xsd");
let xsd = SchemaValidationContext::from_parser(&mut xsdparser);
if let Err(errors) = xsd {
for err in &errors {
println!("{}", err.message.as_ref().unwrap());
}
panic!("Failed to parse schema");
}
let mut xsd = xsd.unwrap();
if let Err(errors) = xsd.validate_document(&xml) {
for err in &errors {
println!("{}", err.message.as_ref().unwrap());
}
panic!("Invalid XML accoding to XSD schema");
}
}
|