Overview
This guide documents the API surface of all node types in Moxml, providing clear expectations for developers about which methods are available on which node types.
Node Type Hierarchy
Node (abstract base)
├── Document
├── Element
├── Attribute
├── Text
├── Cdata
├── Comment
├── ProcessingInstruction
├── Declaration
└── DoctypeCommon Node Methods
All node types inherit these methods from Moxml::Node:
Document Navigation
| Method | Description | Always Available? |
|---|---|---|
| Returns the containing document | ✅ Yes |
| Returns the parent node | ✅ Yes |
| Returns a NodeSet of child nodes | ✅ Yes (may be empty) |
| Returns the next sibling node | ✅ Yes (may be nil) |
| Returns the previous sibling node | ✅ Yes (may be nil) |
Tree Manipulation
| Method | Description | Always Available? |
|---|---|---|
| Adds a child node | ✅ Yes |
| Adds a sibling before this node | ✅ Yes |
| Adds a sibling after this node | ✅ Yes |
| Removes this node from the tree | ✅ Yes |
| Replaces this node with another | ✅ Yes |
Serialization
| Method | Description | Always Available? |
|---|---|---|
| Serializes node to XML string | ✅ Yes |
| Creates a deep copy of the node | ✅ Yes |
XPath Queries
| Method | Description | Always Available? |
|---|---|---|
| Returns NodeSet matching XPath | ✅ Yes (adapter-dependent) |
| Returns first node matching XPath | ✅ Yes (adapter-dependent) |
Type Checking
| Method | Description | Always Available? |
|---|---|---|
| Returns true if node is an Element | ✅ Yes |
| Returns true if node is a Text node | ✅ Yes |
| Returns true if node is a CDATA section | ✅ Yes |
| Returns true if node is a Comment | ✅ Yes |
| Returns true if node is a PI | ✅ Yes |
| Returns true if node is a Document | ✅ Yes |
| Returns true if node is a Declaration | ✅ Yes |
| Returns true if node is a Doctype | ✅ Yes |
| Returns true if node is an Attribute | ✅ Yes |
Node Type-Specific APIs
Document
The root document node.
Additional Methods
| Method | Description | Always Available? |
|---|---|---|
| Returns the root element | ✅ Yes |
| Sets the root element | ✅ Yes |
| Returns document encoding | ✅ Yes |
| Creates a new element | ✅ Yes |
| Creates a new text node | ✅ Yes |
| Creates a new comment | ✅ Yes |
| Creates a new CDATA section | ✅ Yes |
| Creates a new processing instruction | ✅ Yes |
| Creates a new XML declaration | ✅ Yes (adapter-dependent) |
Element
Elements are the primary structural nodes with tag names, attributes, and children.
Identity Methods
| Method | Description | Always Available? |
|---|---|---|
| Returns the element tag name | ✅ Yes |
| Sets the element tag name | ✅ Yes |
| Returns the primary identifier (same as #name) | ✅ Yes |
Namespace Methods
| Method | Description | Always Available? |
|---|---|---|
| Returns the element’s namespace | ✅ Yes (may be nil) |
| Sets the element’s namespace | ✅ Yes |
| Returns the namespace prefix | ✅ Yes (may be nil) |
| Returns the namespace URI | ✅ Yes (may be nil) |
| Returns all namespace definitions | ✅ Yes |
| Adds a namespace definition | ✅ Yes |
Attribute
Attributes are name-value pairs attached to elements.
Identity Methods
| Method | Description | Always Available? |
|---|---|---|
| Returns the attribute name | ✅ Yes |
| Sets the attribute name | ✅ Yes |
| Returns the primary identifier (same as #name) | ✅ Yes |
Text
Text nodes contain character data.
Cdata
CDATA sections contain character data that should not be parsed.
Comment
Comment nodes contain XML comments.
ProcessingInstruction
Processing instructions provide directives to applications.
Declaration
XML declarations specify document metadata.
Property Methods
| Method | Description | Always Available? |
|---|---|---|
| Returns XML version (e.g., "1.0") | ✅ Yes |
| Sets XML version | ✅ Yes |
| Returns character encoding | ✅ Yes (may be nil) |
| Sets character encoding | ✅ Yes |
| Returns standalone status | ✅ Yes (may be nil) |
| Sets standalone status | ✅ Yes |