[][src]Crate sxd_document

use sxd_document::Package;
let package = Package::new();
let doc = package.as_document();

let hello = doc.create_element("hello");
hello.set_attribute_value("planet", "Earth");
let comment = doc.create_comment("What about other planets?");
let text = doc.create_text("Greetings, Earthlings!");


Memory and ownership

The Package struct is responsible for owning every node in the document. Strings are interned, allowing repeated text to consume less memory. This is very useful for documents containing lots of the same attributes and tag names.

The flip side of this decision is that allocated nodes and strings are not deallocated until the entire Package is dropped. This is a reasonable decision for two common cases: building up an XML document and reading an XML document. You may wish to perform large modifications to your data before creating a document.

Namespaces, QNames, and Prefixes

The names of elements and attributes may use namespaces. XML namespacing uses URIs to uniquely distinguish items with the same local name. A qualified name (QName) combines this optional URI with the local name.

When an XML document is represented as text, namespaces are given a shorthand reference known as a prefix. Prefix names are non-authoritative, and only the URI can be used to namespace a name.

Elements and attributes may specify a preferred prefix, which is an indication of what the user would like to be used as a prefix. There are times where the preferred prefix would cause a conflict, and so an autogenerated prefix will be used instead.

Design decisions

Try to leverage the type system as much as possible.



A traditional DOM tree interface for navigating and manipulating XML documents.


Converts XML strings into a DOM structure


Formats a DOM structure to a Write



The main entrypoint to an XML document


A prefixed name. This represents what is found in the string form of an XML document, and does not apply any namespace mapping.


A namespace-qualified name. This represents the name of an element or attribute after the prefix has been mapped to a specific namespace.



Predicates used when parsing an characters in an XML document.