Expand description
Xot is an XML library that lets you access manipulate XML documents as a tree in memory.
use xot::Xot;
let mut xot = Xot::new();
let root = xot.parse("<p>Example</p>")?;
let doc_el = xot.document_element(root)?;
let txt = xot.first_child(doc_el).unwrap();
let txt_value = xot.text_mut(txt).unwrap();
txt_value.set("Hello, world!");
assert_eq!(xot.to_string(root)?, "<p>Hello, world!</p>");§Xot approach
Xot exposes a single Xot struct that you use to access, create and
manipulate all your XML data. Multiple XML trees can exist in an Xot
struct at the same time, and you’re free to move nodes between these trees.
Node is a lightweight handle to a node in the XML tree that you use
with Xot for both access and manipulation. To navigate the tree use
accessors such as Xot::first_child or iterators such a
Xot::children. You then use operations such as Xot::append to
manipulate the tree.
To access and manipulate XML specific data, you use the Value for a
node. This is an enum that’s either an Element, Text, Comment
or ProcessingInstruction, Attribute, Namespace or Document
(which has no value). You can use Xot::value to get the Value.
Sometimes it’s more handy to use the specific accessors for a value, such a
Xot::element or Xot::text.
XML names and namespaces in Xot are referenced by ids. In order to
construct or compare an element, you first need to get hold of a name. To
access a name, use Xot::name. To create a new name if necessary, use
Xot::add_name. To construct a name with a namespace, use
Xot::add_namespace and then Xot::add_name_ns. To create a namespace
prefix, use Xot::add_prefix. You can also use the xmlname module to
manage names; see xmlname::CreateName for a bunch of convenient ways to
create names, for instance.
Attributes and namespace access is most conveniently done through the
Xot::attributes and Xot::namespaces accessors. Manipulation is most
conveniently done through their mutable variants Xot::attributes_mut
and Xot::namespaces_mut.
In some cases however you may want to be able to create namespace and
attribute nodes directly. This can be done through the
Xot::new_namespace_node and Xot::new_attribute_node APIs.
You can also create Xot nodes from a fixed structure, the fixed
submodule.
Modules§
- fixed
- A fixed representation of a tree of nodes.
- output
- Xot offers functionality to serialize XML data in different ways.
- proptest
- Proptest support for Xot
- xmlname
- This module allows you to use XML names in various ways.
Structs§
- Attribute
- Represents an attribute node.
- Comment
- XML comment.
- Element
- XML element name.
- Html5
- Serialize a Xot node to HTML5
- Mutable
Node Map - A
MutableNodeMapis a struct with a hash-map like API and is used to expose attribute and namespace prefix information in a mutable way. - NameId
- Id uniquely identifying a name and namespace.
- Namespace
- Represents a namespace node.
- Namespace
Id - Id uniquely identifying namespace.
- Node
- A node in the XML tree. This is a lightweight value and can be copied.
- NodeMap
- A
NodeMapis a struct with a hash-map like API and is used to expose attribute and namespace prefix information. - Prefix
Id - Id uniquely identifying a prefix
- Processing
Instruction - XML processing instruction value.
- Span
- A span with a start and end position
- Span
Info - Span information for a parsed XML document.
- Text
- XML text value.
- Xot
- The
Xotstruct manages all XML tree data in your program. It lets you access and manipulate one or more XML documents and fragments, as well as unattached trees of nodes.
Enums§
- Axis
- Traversal axis.
- Entry
- Entry for an existing key-value pair or a vacant location to insert one.
- Error
- Xot errors
- Level
Order - Node in level order
- Node
Edge - Node edges.
- Parse
Error - An error that occurred during parsing.
- Span
Info Key - A key to use to look up span information using
SpanInfo::get - Value
- An XML value.
- Value
Type - The type of the XML node.
Type Aliases§
- Attributes
- Attributes of an element.
- Mutable
Attributes - Mutable attributes of an element.
- Mutable
Namespaces - A mutable map of namespace prefixes to namespace ids.
- Namespaces
- A map of namespace prefixes to namespace ids.
- Prefixes
- A map of PrefixId to NamespaceId for namespace tracking.