#[repr(C)]pub struct Node<'doc> {
pub kind: NodeKind,
pub name: &'doc str,
pub namespace: Cell<Option<&'doc Namespace<'doc>>>,
pub first_attribute: Cell<Option<&'doc Attribute<'doc>>>,
pub last_attribute: Cell<Option<&'doc Attribute<'doc>>>,
pub first_child: Cell<Option<&'doc Node<'doc>>>,
pub last_child: Cell<Option<&'doc Node<'doc>>>,
pub parent: Cell<Option<&'doc Node<'doc>>>,
pub next_sibling: Cell<Option<&'doc Node<'doc>>>,
pub prev_sibling: Cell<Option<&'doc Node<'doc>>>,
pub content: Cell<Option<&'doc str>>,
pub line: u32,
}Expand description
A node in the XML tree. One struct for every kind; fields are used per-kind.
§Layout (libxml2 mirror)
The struct is #[repr(C)] with field order chosen to align with
_xmlNode in libxml2. When we later expose an extern "C" shim,
callers can treat *mut Node as xmlNode* (modulo a few private slots
we may still need to add — _private, psvi, etc.).
§Field usage by kind
| Kind | name | content | first_* / last_* |
|---|---|---|---|
Element | tag name | unused ("") | children + attrs |
Text | "" | text data | unused |
CData | "" | CDATA payload | unused |
Comment | "" | comment text | unused |
Pi | target | content after target | unused |
Fields§
§kind: NodeKind§name: &'doc str§namespace: Cell<Option<&'doc Namespace<'doc>>>§first_attribute: Cell<Option<&'doc Attribute<'doc>>>Linked-list head for element attributes (None for non-elements).
last_attribute: Cell<Option<&'doc Attribute<'doc>>>§first_child: Cell<Option<&'doc Node<'doc>>>§last_child: Cell<Option<&'doc Node<'doc>>>§parent: Cell<Option<&'doc Node<'doc>>>§next_sibling: Cell<Option<&'doc Node<'doc>>>§prev_sibling: Cell<Option<&'doc Node<'doc>>>§content: Cell<Option<&'doc str>>Text/CData/Comment/Pi payload. None mirrors libxml2’s NULL
content — notably a processing instruction with no data
(<?foo?>), which serializes without the trailing space that a
PI carrying a (possibly empty) data section gets.
line: u321-based source line of the opening tag. 0 for nodes constructed programmatically.
Implementations§
Source§impl<'doc> Node<'doc>
impl<'doc> Node<'doc>
pub fn is_element(&self) -> bool
pub fn is_text(&self) -> bool
pub fn is_entity_ref(&self) -> bool
Sourcepub fn name(&self) -> &'doc str
pub fn name(&self) -> &'doc str
Element name (or PI target for PI nodes). Empty "" for
Text/CData/Comment.
Prefer this method over direct node.name field access in
internal / downstream code. The pub name field stays
stable on the lean rlib build, but when sup-xml is built with
the c-abi feature the storage type changes to a thin
NUL-terminated ArenaCStr. This method returns &str on
both configs — direct field access does not.
Sourcepub fn content(&self) -> &'doc str
pub fn content(&self) -> &'doc str
Text payload for Text/CData/Comment/Pi nodes; "" for
elements. See name for why to prefer this
method over direct field access.
Sourcepub fn content_opt(&self) -> Option<&'doc str>
pub fn content_opt(&self) -> Option<&'doc str>
The payload as libxml2 stores it: None when the underlying
content pointer is NULL, Some (possibly "") otherwise.
Most callers want content; the serializer uses
this to reproduce libxml2’s PI rule (a NULL-data PI omits the
space a non-NULL-but-empty-data PI emits).
Sourcepub fn set_content(&self, arena: &'doc DocumentBuilder, content: &'doc str)
pub fn set_content(&self, arena: &'doc DocumentBuilder, content: &'doc str)
Replace the node’s content (text/CData/comment/PI payload). Used by the HTML sink and other in-place tree mutators. Allocates a NUL-terminated copy in the arena when the c-abi feature is on.
arena must be the same DocumentBuilder that owns this node
(lifetimes enforce it).
Sourcepub fn attributes(&self) -> AttrIter<'doc> ⓘ
pub fn attributes(&self) -> AttrIter<'doc> ⓘ
Iterate attributes in document order. Returns an empty iterator for non-elements.
Sourcepub fn local_name(&self) -> &'doc str
pub fn local_name(&self) -> &'doc str
Local part of this element/attr-like node’s name — "foo" for both
<foo/> and <ns:foo/>. On the lean build name
returns the full QName including any prefix; on the c-abi build
the prefix is stripped at parse time and name() is already the
local part. local_name() is the layout-agnostic accessor:
callers that want to match by local name should use this.
Sourcepub fn ns_declarations(&self) -> NsDeclIter<'doc> ⓘ
pub fn ns_declarations(&self) -> NsDeclIter<'doc> ⓘ
Iterate this element’s xmlns declarations as (prefix, href) —
prefix is None for the default namespace (xmlns="..."),
Some("dc") for xmlns:dc="...". Empty for non-elements.
Storage differs by build: the c-abi build keeps xmlns declarations
on the element’s ns_def chain (matching libxml2’s _xmlNode);
the lean build keeps them in attributes
instead. A namespace-blind parse (namespace_aware: false) does
no namespace processing and leaves xmlns declarations in the
attribute list under either build, so the c-abi iterator walks
ns_def first and then the attribute list — the two are mutually
exclusive (a given parse populates one or the other), so nothing is
reported twice. Callers see every declaration regardless of build
or parse mode.
Sourcepub fn find_child(&self, name: &str) -> Option<&'doc Node<'doc>>
pub fn find_child(&self, name: &str) -> Option<&'doc Node<'doc>>
First child element matching name, or None. O(n) walk; for repeated
lookups, iterate children() yourself.
Sourcepub fn text_content(&self) -> Option<&'doc str>
pub fn text_content(&self) -> Option<&'doc str>
For text-bearing kinds returns the content; for elements returns the
first text-or-CDATA child’s content; otherwise None.