babbel_xml 0.3.0

Full-featured XML parser, validator, stringifier, and XPath 1.0 engine in pure Rust
Documentation
//! XML Format Engine adhering to OCP and DIP.

use babbel_core::{
    BabbelError, FormatEngine, FormatOptions, Value,
    io::{IDestination, ISource},
};

/// XML format engine implementing [`FormatEngine`].
#[derive(Debug, Default, Clone, Copy)]
pub struct XmlEngine;

impl FormatEngine for XmlEngine {
    fn format_id(&self) -> &'static str {
        "xml"
    }

    fn mime_type(&self) -> &'static str {
        "application/xml"
    }

    fn file_extensions(&self) -> &'static [&'static str] {
        &["xml"]
    }

    fn parse(&self, source: &mut dyn ISource) -> Result<Value, BabbelError> {
        let doc = crate::parse_source(source)?;
        Ok(doc.to_value())
    }

    fn serialize(
        &self,
        value: &Value,
        destination: &mut dyn IDestination,
        _options: &FormatOptions,
    ) -> Result<(), BabbelError> {
        value.serialize_xml(destination, None);
        Ok(())
    }
}