pub struct Document { /* private fields */ }Implementations§
Source§impl Document
impl Document
Sourcepub fn new(root: impl Into<NewElement>) -> Self
pub fn new(root: impl Into<NewElement>) -> Self
Create a new document with the specified element as root.
See NewElement for what root accepts.
assert_eq!(
xmlem::Document::new("root").to_string(),
r#"<root/>"#,
);
assert_eq!(
xmlem::Document::new(("a", [("b", "c")])).to_string(),
r#"<a b="c"/>"#,
);§Panics
This method panics if root contains non-representable element or attribute names.
pub fn sort(&mut self, elements: bool)
Sourcepub fn set_declaration(&mut self, decl: Option<Declaration>)
pub fn set_declaration(&mut self, decl: Option<Declaration>)
Examples found in repository?
examples/readme.rs (line 18)
5fn main() {
6 let mut doc = Document::from_str("<root><potato /></root>").unwrap();
7 let root = doc.root();
8
9 let potato = root
10 .query_selector(&doc, &Selector::new("potato").unwrap())
11 .unwrap();
12 potato.append_new_element(
13 &mut doc,
14 ("wow", [("easy", "true"), ("x", "200"), ("a-null", "\0")]),
15 );
16
17 let decl = Declaration::v1_1();
18 doc.set_declaration(Some(decl));
19 doc.set_doctype(Some("not-html"));
20
21 println!("{}", doc.to_string_pretty());
22}pub fn declaration(&self) -> Option<&Declaration>
Sourcepub fn set_doctype(&mut self, doctype: Option<&str>)
pub fn set_doctype(&mut self, doctype: Option<&str>)
Examples found in repository?
examples/readme.rs (line 19)
5fn main() {
6 let mut doc = Document::from_str("<root><potato /></root>").unwrap();
7 let root = doc.root();
8
9 let potato = root
10 .query_selector(&doc, &Selector::new("potato").unwrap())
11 .unwrap();
12 potato.append_new_element(
13 &mut doc,
14 ("wow", [("easy", "true"), ("x", "200"), ("a-null", "\0")]),
15 );
16
17 let decl = Declaration::v1_1();
18 doc.set_declaration(Some(decl));
19 doc.set_doctype(Some("not-html"));
20
21 println!("{}", doc.to_string_pretty());
22}pub fn doctype(&self) -> Option<&str>
Sourcepub fn root(&self) -> Element
pub fn root(&self) -> Element
Examples found in repository?
examples/readme.rs (line 7)
5fn main() {
6 let mut doc = Document::from_str("<root><potato /></root>").unwrap();
7 let root = doc.root();
8
9 let potato = root
10 .query_selector(&doc, &Selector::new("potato").unwrap())
11 .unwrap();
12 potato.append_new_element(
13 &mut doc,
14 ("wow", [("easy", "true"), ("x", "200"), ("a-null", "\0")]),
15 );
16
17 let decl = Declaration::v1_1();
18 doc.set_declaration(Some(decl));
19 doc.set_doctype(Some("not-html"));
20
21 println!("{}", doc.to_string_pretty());
22}Sourcepub fn to_string_pretty(&self) -> String
pub fn to_string_pretty(&self) -> String
Examples found in repository?
examples/readme.rs (line 21)
5fn main() {
6 let mut doc = Document::from_str("<root><potato /></root>").unwrap();
7 let root = doc.root();
8
9 let potato = root
10 .query_selector(&doc, &Selector::new("potato").unwrap())
11 .unwrap();
12 potato.append_new_element(
13 &mut doc,
14 ("wow", [("easy", "true"), ("x", "200"), ("a-null", "\0")]),
15 );
16
17 let decl = Declaration::v1_1();
18 doc.set_declaration(Some(decl));
19 doc.set_doctype(Some("not-html"));
20
21 println!("{}", doc.to_string_pretty());
22}pub fn to_string_pretty_with_config(&self, config: &Config) -> String
pub fn from_file(file: File) -> Result<Document, ReadError>
pub fn from_reader<R: BufRead>(reader: R) -> Result<Document, ReadError>
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Document
impl RefUnwindSafe for Document
impl Send for Document
impl Sync for Document
impl Unpin for Document
impl UnwindSafe for Document
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more