pub struct SchemaValidator { /* private fields */ }Expand description
XSD Schema Validator
Validates XML documents against XSD schemas with comprehensive error reporting.
Implementations§
Source§impl SchemaValidator
impl SchemaValidator
Sourcepub fn from_xsd(xsd: &str) -> Result<Self, ValidationError>
pub fn from_xsd(xsd: &str) -> Result<Self, ValidationError>
Create a new validator from XSD schema string.
§Arguments
xsd- XSD schema definition as a string
§Errors
Returns ValidationError::SchemaParseError if the schema is malformed.
§Example
use hedl_xml::schema::SchemaValidator;
let schema = r#"<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="root" type="xs:string"/>
</xs:schema>"#;
let validator = SchemaValidator::from_xsd(schema)?;Sourcepub fn from_file(path: &Path) -> Result<Self, ValidationError>
pub fn from_file(path: &Path) -> Result<Self, ValidationError>
Create a new validator from XSD schema file.
§Arguments
path- Path to XSD schema file
§Errors
Returns ValidationError::SchemaNotFound if file doesn’t exist,
ValidationError::IoError for I/O errors, or
ValidationError::SchemaParseError if schema is malformed.
§Example
use hedl_xml::schema::SchemaValidator;
use std::path::Path;
let validator = SchemaValidator::from_file(Path::new("schema.xsd"))?;Sourcepub fn validate(&self, xml: &str) -> Result<(), ValidationError>
pub fn validate(&self, xml: &str) -> Result<(), ValidationError>
Validate an XML document against the schema.
§Arguments
xml- XML document to validate
§Errors
Returns various ValidationError variants if validation fails.
§Example
use hedl_xml::schema::SchemaValidator;
let schema = r#"<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="root" type="xs:string"/>
</xs:schema>"#;
let validator = SchemaValidator::from_xsd(schema)?;
let xml = r#"<?xml version="1.0"?><root>value</root>"#;
validator.validate(xml)?;Trait Implementations§
Source§impl Clone for SchemaValidator
impl Clone for SchemaValidator
Source§fn clone(&self) -> SchemaValidator
fn clone(&self) -> SchemaValidator
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for SchemaValidator
impl RefUnwindSafe for SchemaValidator
impl Send for SchemaValidator
impl Sync for SchemaValidator
impl Unpin for SchemaValidator
impl UnwindSafe for SchemaValidator
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more