pub fn document(text: &str) -> Result<Xml<'_>, Error>Expand description
Parse an XML document.
Only UTF-8 encoding is supported. XML declaration is optional.
ยงExamples
Parse a document:
let text = r#"<?xml?><can><beans kind="fava">Cool Beans</beans><sauce></sauce></can>"#;
let xml = xmlite::document(text).unwrap();
eprintln!("{xml:?}");
assert_eq!(xml.name(), Some("can"));
assert_eq!(xml.children().next().unwrap().name(), Some("beans"));
assert_eq!(xml.children().next().unwrap().attr("kind"), Some("\"fava\""));Mutate the document afterwards:
let text = r#"<?xml?><bag><pastry kind="danish" /></bag>"#;
let mut xml = xmlite::document(text).unwrap();
let attr = xml.children_mut().find(|e| e.name() == Some("pastry")).unwrap().attr_mut("kind");
*attr.unwrap() = "berliner".to_owned();