Parsing
XmlDeserializer turns XML input into
an XmlDocument tree. It reads the XML
declaration, normalizes line breaks, resolves namespaces and preserves comments.
From a byte vector or string
Section titled “From a byte vector or string”use draviavemal_xml_rs::XmlDeserializer;
let xml = r#"<note><to>World</to></note>"#;let document = XmlDeserializer::vec_to_xml_doc_tree(xml.as_bytes().to_vec())?;vec_to_xml_doc_tree takes a Vec<u8>, so pass your_string.as_bytes().to_vec()
for an in-memory string.
From a file
Section titled “From a file”use draviavemal_xml_rs::XmlDeserializer;
let document = XmlDeserializer::file_to_xml_doc_tree("catalog.xml")?;What is preserved
Section titled “What is preserved”| Input | Handling |
|---|---|
| XML declaration | version and encoding are read onto the document (encoding defaults to utf-8). |
| Namespaces | Prefix → URI mappings are resolved; QNames keep their prefix. |
| Attributes | Kept in source order. |
| Text & mixed content | Unescaped and stored as text nodes. |
| Comments | Preserved as comment nodes and re-emitted on serialize. |
| Self-closing tags | Parsed as empty elements. |
- Navigating & querying the parsed tree.
- Building & editing documents from scratch.