Skip to content

This content is for v2.x version. Switch to the Stable version.

Parsing

XmlDeserializer turns XML input into an XmlDocument tree. It reads the XML declaration, normalizes line breaks, resolves namespaces and preserves comments.

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.

use draviavemal_xml_rs::XmlDeserializer;
let document = XmlDeserializer::file_to_xml_doc_tree("catalog.xml")?;
InputHandling
XML declarationversion and encoding are read onto the document (encoding defaults to utf-8).
NamespacesPrefix → URI mappings are resolved; QNames keep their prefix.
AttributesKept in source order.
Text & mixed contentUnescaped and stored as text nodes.
CommentsPreserved as comment nodes and re-emitted on serialize.
Self-closing tagsParsed as empty elements.

After parsing, the XML declaration values are available on the document:

let version = document.get_version(); // e.g. "1.0"
let encoding = document.get_encoding(); // e.g. "UTF-8"
let standalone = document.get_standalone(); // Option<&str>
let prolog = document.get_prolog_comments(); // comments before the root