#[repr(C)]pub struct Attribute<'doc> {
pub name: &'doc str,
pub namespace: Cell<Option<&'doc Namespace<'doc>>>,
pub value: &'doc str,
pub next: Cell<Option<&'doc Attribute<'doc>>>,
pub prev: Cell<Option<&'doc Attribute<'doc>>>,
pub parent: Cell<Option<&'doc Node<'doc>>>,
}Expand description
An attribute on an element. Belongs to a doubly-linked list rooted at
Node::first_attribute / Node::last_attribute on its owning element.
§Layout
libxml2’s _xmlAttr shares its first 8 fields with _xmlNode:
generic walkers cast xmlAttr* to xmlNode* and read .type /
.name. Under the c-abi feature this struct’s layout matches
_xmlAttr byte-exact.
libxml2 _xmlAttr (64-bit):
void *_private; // offset 0
xmlElementType type; // offset 8 (XML_ATTRIBUTE_NODE = 2)
const xmlChar *name; // offset 16
xmlNode *children; // offset 24 (text/entity content nodes)
xmlNode *last; // offset 32
xmlNode *parent; // offset 40 (the element)
xmlAttr *next; // offset 48
xmlAttr *prev; // offset 56
xmlDoc *doc; // offset 64
xmlNs *ns; // offset 72
xmlAttributeType atype; // offset 80 (DTD type info)
void *psvi; // offset 88
...Fields§
§name: &'doc str§namespace: Cell<Option<&'doc Namespace<'doc>>>§value: &'doc strAlready entity-expanded by the parser.
next: Cell<Option<&'doc Attribute<'doc>>>§prev: Cell<Option<&'doc Attribute<'doc>>>§parent: Cell<Option<&'doc Node<'doc>>>Element this attribute belongs to. None only for a freshly-allocated
attribute not yet attached via DocumentBuilder::append_attribute.
Implementations§
Source§impl<'doc> Attribute<'doc>
impl<'doc> Attribute<'doc>
Sourcepub fn name(&self) -> &'doc str
pub fn name(&self) -> &'doc str
Attribute name (xlink:href, id, etc.).
Prefer this method over direct attr.name field access.
The pub name field stays stable on the lean rlib build; in
the c-abi build it becomes a thin NUL-terminated
ArenaCStr. This method returns &str either way.
Sourcepub fn local_name(&self) -> &'doc str
pub fn local_name(&self) -> &'doc str
The attribute’s local name (the part after any prefix:).
Layout-agnostic, mirroring Node::local_name: on the lean
build name is the full QName, while on the
c-abi build the prefix is stripped at parse time so name()
is already local. Callers matching a namespaced attribute by
its local part should use this rather than name().
Sourcepub fn value(&self) -> &'doc str
pub fn value(&self) -> &'doc str
Attribute value (entity-expanded by the parser). Same
rationale as name for preferring this over
direct field access.
In the c-abi build, attribute values are stored two ways:
the sup-xml-only value slot (set by our parser /
new_attribute API) and the libxml2-standard text-node
chain rooted at children (the path libxslt writes to when
it builds attributes during an XSLT transform — it doesn’t
know about our tail field). When value is empty, fall
back to walking children so attributes built post-parse
by libxslt still report the right text.