Debian Codegraph @

examples/schema_example.rs

raw symbols SCIP
1 //!
2 //! Example Usage of XSD Schema Validation
3 //!
4 use libxml::schemas::SchemaParserContext;
5 use libxml::schemas::SchemaValidationContext;
6
7 use libxml::parser::Parser;
8
9 fn main() {
10 let xml = Parser::default()
11 .parse_file("tests/resources/schema.xml")
12 .expect("Expected to be able to parse XML Document from file");
13
14 let mut xsdparser = SchemaParserContext::from_file("tests/resources/schema.xsd");
15 let xsd = SchemaValidationContext::from_parser(&mut xsdparser);
16
17 if let Err(errors) = xsd {
18 for err in &errors {
19 println!("{}", err.message.as_ref().unwrap());
20 }
21
22 panic!("Failed to parse schema");
23 }
24
25 let mut xsd = xsd.unwrap();
26
27 if let Err(errors) = xsd.validate_document(&xml) {
28 for err in &errors {
29 println!("{}", err.message.as_ref().unwrap());
30 }
31
32 panic!("Invalid XML accoding to XSD schema");
33 }
34 }