1use self::{declaration::Declaration, element::Element};
2use std::error::Error;
3
4pub mod attributes;
5pub mod declaration;
6pub mod element;
7
8pub struct Document {
9 pub declaration: Declaration,
10 pub root: Element,
11}
12
13impl Document {}
14
15pub fn parse(text: &str) -> Result<Document, Box<dyn Error>> {
17 if text.is_empty() {
19 return Err("Empty XML document".into());
20 }
21
22 let (declaration, declaration_end_position) = declaration::parse(text)?;
24
25 let (root, root_element_end_position) = element::parse(&text[declaration_end_position..])?;
27
28 if declaration_end_position + root_element_end_position > text.len() {
30 return Err("Remaining unparsed text in XML document".into());
31 }
32
33 Ok(Document { declaration, root })
34}
35
36