Skip to main content

ofx_rs/xml/
mod.rs

1//! XML parsing infrastructure for OFX documents.
2
3pub mod helpers;
4pub mod reader;
5
6use core::fmt;
7
8pub use reader::OfxReader;
9
10/// Error type for XML-level parsing failures.
11#[non_exhaustive]
12#[derive(Debug, Clone, PartialEq, Eq)]
13pub enum XmlError {
14    /// The XML document was malformed.
15    MalformedXml { message: String },
16    /// An unexpected element was encountered.
17    UnexpectedElement { expected: String, found: String },
18    /// A required element was missing from its parent.
19    MissingElement { parent: String, element: String },
20    /// An element contained invalid text content.
21    InvalidContent {
22        element: String,
23        value: String,
24        reason: String,
25    },
26}
27
28impl fmt::Display for XmlError {
29    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
30        match self {
31            Self::MalformedXml { message } => {
32                write!(f, "malformed XML: {message}")
33            }
34            Self::UnexpectedElement { expected, found } => {
35                write!(f, "expected element <{expected}>, found <{found}>")
36            }
37            Self::MissingElement { parent, element } => {
38                write!(f, "missing required element <{element}> in <{parent}>")
39            }
40            Self::InvalidContent {
41                element,
42                value,
43                reason,
44            } => {
45                write!(
46                    f,
47                    "invalid content in <{element}>: '{value}' ({reason})"
48                )
49            }
50        }
51    }
52}
53
54impl std::error::Error for XmlError {}