declxml
declxml
declxml
is a Rust crate that lets you declare XML trees at compile time
with macros and provides deserializers with derive macros.
Namespaces, attributes, and element names are checked during macro expansion.
Features
xml!
macro for inline XML AST construction.- Pre-sorted attributes and namespaces for Exclusive C14N serialization.
- Pre-escaped literal values for safe XML output.
- Produces a lightweight AST (
Element
,Attr
, etc.) that can be serialized directly without runtime sorting.
Assumptions
- Tag names are known at compile time.
- Namespaces and their URIs are known at compile time.
- Attribute names are known at compile time, while their values can be dynamic.
Strict Namespace Model
declxml
enforces a strict namespace model to simplify canonicalization:
-
Elements and attributes may be either:
- Un-namespaced: no prefix, no associated namespace, or
- Prefixed: a declared prefix must always be used (e.g.
example:root
).
-
The XML default namespace form (
<Element xmlns="…">
) is not allowed. If you want to use a namespace, declare it in the@ns
block and use the prefix consistently (example:Element
).
Example
use xml;
let doc = xml! ;