-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinspect_schema.rs
More file actions
58 lines (48 loc) · 1.83 KB
/
inspect_schema.rs
File metadata and controls
58 lines (48 loc) · 1.83 KB
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
//! Schema Inspection Example
//!
//! This example demonstrates how to parse and inspect an XSD schema,
//! examining its elements, types, and structure.
//!
//! Run with: cargo run --example inspect_schema
use std::path::PathBuf;
use xmlschema::validators::{FormDefault, GlobalType, XsdSchema};
fn main() -> Result<(), Box<dyn std::error::Error>> {
let examples_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("examples/data");
let schema_path = examples_dir.join("book.xsd");
println!("=== Schema Inspection Example ===\n");
println!("Loading: {}\n", schema_path.display());
let schema = XsdSchema::from_file(&schema_path)?;
// Basic schema information
println!("--- Schema Metadata ---");
println!("Target Namespace: {:?}", schema.target_namespace);
println!(
"Element Form Default: {}",
match schema.element_form_default {
FormDefault::Qualified => "qualified",
FormDefault::Unqualified => "unqualified",
}
);
// Count components
let elements = &schema.maps.global_maps.elements;
let types = &schema.maps.global_maps.types;
let groups = &schema.maps.global_maps.groups;
println!("\n--- Component Counts ---");
println!("Global Elements: {}", elements.len());
println!("Global Types: {}", types.len());
println!("Model Groups: {}", groups.len());
// List global elements
println!("\n--- Global Elements ---");
for (name, _elem) in elements.iter() {
println!(" - {}", name.local_name);
}
// List global types
println!("\n--- Global Types ---");
for (name, type_def) in types.iter() {
let kind = match type_def {
GlobalType::Simple(_) => "simple",
GlobalType::Complex(_) => "complex",
};
println!(" - {} ({})", name.local_name, kind);
}
Ok(())
}