Skip to main content

xml_3dm/xml/
mod.rs

1//! XML parsing and output.
2//!
3//! This module provides XML parsing and printing functionality that matches
4//! the Java implementation's behavior for byte-for-byte compatibility.
5
6mod parser;
7mod printer;
8
9pub use parser::{parse_file, parse_str, XmlParser};
10pub use printer::{print_to_string, print_to_string_pretty, XmlPrinter, XmlPrinterOptions};
11
12use crate::node::{NodeRef, XmlContent};
13
14/// Factory trait for creating nodes during parsing.
15///
16/// This allows the parser to create either BaseNode or BranchNode trees
17/// depending on the context.
18pub trait NodeFactory {
19    /// Creates a new node with the given content.
20    fn make_node(&self, content: XmlContent) -> NodeRef;
21}
22
23/// Factory that creates base nodes.
24pub struct BaseNodeFactory;
25
26impl NodeFactory for BaseNodeFactory {
27    fn make_node(&self, content: XmlContent) -> NodeRef {
28        crate::node::new_base_node(Some(content))
29    }
30}
31
32/// Factory that creates branch nodes.
33pub struct BranchNodeFactory;
34
35impl NodeFactory for BranchNodeFactory {
36    fn make_node(&self, content: XmlContent) -> NodeRef {
37        crate::node::new_branch_node(Some(content))
38    }
39}