#![forbid(unsafe_code)]
#![warn(missing_docs)]
#![warn(rustdoc::missing_crate_level_docs)]
pub mod arena;
pub mod document;
pub mod entity;
pub mod error;
pub mod handle;
pub mod iter;
pub mod node;
pub(crate) mod parser;
pub mod printer;
pub mod refs;
pub mod typed;
pub mod util;
pub mod visitor;
pub use arena::NodeId;
pub use document::Document;
pub use error::{ParseErrorKind, Result, XmlError};
pub use handle::{Handle, HandleMut};
pub use iter::{Attributes, ChildElements, Children, Descendants, Siblings};
pub use node::{Attribute, ElementData, NodeData, NodeKind, TextData};
pub use printer::XmlPrinter;
pub use refs::{ElementRef, NodeRef};
pub use visitor::XmlVisitor;
pub type Printer = XmlPrinter;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum Whitespace {
#[default]
Preserve,
Collapse,
Pedantic,
}
#[derive(Debug, Clone)]
pub struct ParseOptions {
pub process_entities: bool,
pub whitespace: Whitespace,
pub max_depth: u32,
}
impl ParseOptions {
#[must_use]
pub const fn new() -> Self {
Self {
process_entities: true,
whitespace: Whitespace::Preserve,
max_depth: 500,
}
}
#[must_use]
pub const fn with_whitespace(mut self, whitespace: Whitespace) -> Self {
self.whitespace = whitespace;
self
}
#[must_use]
pub const fn with_process_entities(mut self, process: bool) -> Self {
self.process_entities = process;
self
}
#[must_use]
pub const fn with_max_depth(mut self, depth: u32) -> Self {
self.max_depth = depth;
self
}
}
impl Default for ParseOptions {
fn default() -> Self {
Self::new()
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn whitespace_default() {
assert_eq!(Whitespace::default(), Whitespace::Preserve);
}
#[test]
fn parse_options_defaults() {
let opts = ParseOptions::new();
assert!(opts.process_entities);
assert_eq!(opts.whitespace, Whitespace::Preserve);
assert_eq!(opts.max_depth, 500);
}
#[test]
fn parse_options_builder() {
let opts = ParseOptions::new()
.with_whitespace(Whitespace::Collapse)
.with_process_entities(false)
.with_max_depth(100);
assert!(!opts.process_entities);
assert_eq!(opts.whitespace, Whitespace::Collapse);
assert_eq!(opts.max_depth, 100);
}
#[test]
fn parse_options_default_trait() {
let opts = ParseOptions::default();
assert_eq!(opts.max_depth, 500);
}
}