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

Create a blank new xml document.

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

Below are methods for writing xml. The XML will be written in UTF-8.

Trait Implementations

Formats the value using the given formatter. Read more

The associated error which can be returned from parsing.

Parses a string s to return a value of this type. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.