| Crates.io | declxml-macros |
| lib.rs | declxml-macros |
| version | 0.1.0 |
| created_at | 2025-10-01 15:12:20.182351+00 |
| updated_at | 2025-10-01 15:12:20.182351+00 |
| description | `declxml-macros` Used By `declxml` Crate |
| homepage | |
| repository | https://github.com/williamcparks/declxml/ |
| max_upload_size | |
| id | 1862715 |
| size | 4,202 |
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.
xml! macro for inline XML AST construction.Element, Attr, etc.) that can be serialized
directly without runtime sorting.declxml enforces a strict namespace model to simplify canonicalization:
Elements and attributes may be either:
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).
use declxml::xml;
let doc = xml! {
// Namespace Declarations
// Namespaces are declared once, before the root element:
// Undeclared / unused prefix causes a compile-time error.
@ns {
example = "uri:ns",
other = "uri:other",
}
// All documents must start with exactly one root element:
example:root {
// children here
// Empty elements
// Use a trailing semicolon (;) as shorthand for no children
nochildren;
// Attributes
// Declared after the element name, before children.
// Attributes may have prefixes or not
example:withattrs other:id="my_id" {
subchild other:id="other_id";
}
// Dynamic values
// Wrap a Rust expression in parentheses `(…)` to inject it at runtime.
//
// • In attributes: the expression must be "string-like" such as
// `&str`, `String`, `Box<str>`, etc.
// • In children: the expression must be either
// - another XML element (from `xml!`), or
// - any "string-like" type (e.g. `&str`, `String`, `Box<str>`, etc.).
(custom_child)
// Attribute with dynamic value
custom_attr my_attr=(attr_value);
}
};