[][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!");

hello.append_child(comment);
hello.append_child(text);
doc.root().append_child(hello);

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.

Modules

dom

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

parser

Converts XML strings into a DOM structure

writer

Formats a DOM structure to a Write

Structs

Package

The main entrypoint to an XML document

PrefixedName

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

QName

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

Traits

XmlChar

Predicates used when parsing an characters in an XML document.