Skip to content

API Reference

Summary of the public surface. For the always-current, fully generated reference see docs.rs/draviavemal-xml_rs.

use draviavemal_xml_rs::{
XmlDeserializer, XmlSerializer, XmlDocument, XmlElement,
XmlAttribute, XmlElementContentType,
};
TypeDescription
NodeIdu32 identifier of a node within a document.
Tag / NsTagString aliases for a local and namespaced tag name.

XML → XmlDocument. Stateless; call the associated functions.

FunctionReturns
vec_to_xml_doc_tree(xml: Vec<u8>)Result<XmlDocument>
file_to_xml_doc_tree(path: &str)Result<XmlDocument>

XmlDocument → XML. Round-trip safe.

FunctionReturns
xml_tree_to_vec(doc: &mut XmlDocument)Result<Vec<u8>>
xml_doc_tree_to_file(doc: &mut XmlDocument, path: &str)Result<()>

The DOM tree and node store.

MethodPurpose
new() / default()Create an empty document (version 1.0, encoding UTF-8).
get_root_id()NodeId of the root element.
get_element(id) / get_element_mut(id)Look up an element (immutable / mutable).
create_root_element_mut(tag, attrs)Create the root element.
append_child_element_mut(parent, tag, attrs)Append a child; returns its NodeId.
inser_child_element_after_last_tag_mut(...)Insert after the last matching local tag.
inser_child_element_before_first_tag_mut(...)Insert before the first matching local tag.
inser_child_element_after_last_tag_ns_mut(...)Insert after the last matching namespaced tag.
inser_child_element_before_first_tag_ns_mut(...)Insert before the first matching namespaced tag.
find_first_child(parent, tag)First child with the given local tag.
find_all_child(parent, tag)All children with the given local tag.
find_first_by_attribute(start, name, value)First descendant matching an attribute.
set_version_mut / get_versionXML declaration version.
set_encoding_mut / get_encodingXML declaration encoding.

A single element node.

MethodPurpose
get_id() / get_parent_id()Node id / parent id.
get_tag() / get_tag_ns()Local / namespaced tag name.
get_attribute(name) / get_attribute_ns(ns_name)Read an attribute.
get_child_contents()The list of XmlElementContentType.
get_child_element_count()Count of child elements only.
find_first_child(tag)First child element by local tag.
add_attribute_mut(attr)Add an attribute.
remove_attribute_mut(name) / remove_attribute_ns_mut(ns_name)Remove an attribute.
clear_attribute_mut()Remove all attributes.
add_text_mut(text)Add a text node.
add_comments_mut(comment)Add a comment node.
MemberPurpose
new(name, value)Construct; a prefix:name is split into prefix + local name.
get_name()Local name without prefix.
get_ns_name()Namespaced name (prefix:name) when a prefix is present.
get_value()Attribute value.

Enum of an element’s possible children:

VariantHolds
Element((NodeId, Tag, NsTag))A child element reference.
Text(String)A text node.
Comment(String)A comment node.