Struct xml_doc::Document [−][src]
pub struct Document { /* fields omitted */ }
Expand description
Represents a XML document or a document fragment.
Examples
use xml_doc::Document;
let mut doc = Document::parse_str(r#"<?xml version="1.0" encoding="UTF-8"?>
<package>
<metadata>
<author>Lewis Carol</author>
</metadata>
</package>
"#).unwrap();
let author_elem = doc
.root_element()
.unwrap()
.find(&doc, "metadata")
.unwrap()
.find(&doc, "author")
.unwrap();
author_elem.set_text_content(&mut doc, "Lewis Carroll");
let xml = doc.write_str();
Implementations
Get ‘container’ element of Document.
The document uses an invisible ‘container’ element which it uses to manage its root nodes.
Its parent is None, and trying to change its parent will
return Error::ContainerCannotMove
.
For the container element, only its children
is relevant.
Other attributes are not used.
Returns true
if document doesn’t have any nodes.
Returns false
if you added a node or parsed an xml.
You can only call parse_*()
if document is empty.
Get root nodes of document.
Get first root node that is an element.
Push a node to end of root nodes.
If doc has no Element
, pushing a Node::Element
is
equivalent to setting it as root element.
Below are methods for parsing xml.
Call parse_*_with_opts
with custom ReadOptions
to change parser behaviour.
Otherwise, ReadOptions::default()
is used.
Errors
Error::CannotDecode
: Could not decode XML. XML declaration may have invalid encoding value.Error::MalformedXML
: Could not read XML.Error::Io
: IO Error
Below are methods for writing xml. The XML will be written in UTF-8.