Expand description
C FFI compatibility layer for tinyxml2-rs.
This crate provides extern "C" functions that expose the tinyxml2 Rust API
through a C-compatible ABI. It produces both static and shared libraries.
§Safety
This crate necessarily uses unsafe at the FFI boundary. All public functions
validate inputs and catch panics to prevent undefined behavior across the
FFI boundary.
§String Lifetimes
Functions returning *const c_char return pointers to strings cached inside
the TxDocument or TxPrinter wrapper. These pointers remain valid until:
- The wrapper is freed (
tx_document_free/tx_printer_free). - A mutating operation is called on the wrapper (e.g., parse, insert, delete).
Structs§
- TxDocument
- Opaque wrapper around a
Documentfor FFI use. - TxNode
Id - A C-compatible node identifier.
- TxPrinter
- Opaque wrapper around an
XmlPrinterfor FFI use.
Enums§
- TxError
- C-compatible error code enum matching
TinyXML2error values. - TxNode
Type - C-compatible representation of the XML node type.
Constants§
- TX_
NULL_ NODE - Sentinel value representing a null / invalid node.
Functions§
- tx_
bool_ ⚠attribute - Returns a boolean attribute value, or
default_valif the attribute does not exist or cannot be parsed. - tx_
delete_ ⚠child - Deletes
childfromparent. - tx_
delete_ ⚠children - Deletes all children of
parent. - tx_
delete_ ⚠node - Deletes a node and all its descendants from the document.
- tx_
document_ ⚠clear - Clears the document, removing all nodes and resetting to an empty state.
- tx_
document_ ⚠error - Returns the current error code of the document.
- tx_
document_ ⚠error_ line - Returns the line number of the current error, or 0 if no error.
- tx_
document_ ⚠error_ name - Returns the error name string, or null if no error.
- tx_
document_ ⚠free - Frees a document previously created with
tx_document_new. - tx_
document_ ⚠load_ file - Loads and parses an XML file.
- tx_
document_ new - Creates a new, empty XML document.
- tx_
document_ ⚠parse - Parses an XML string into the document, replacing any existing content.
- tx_
document_ ⚠save_ file - Saves the document to a file (pretty-printed).
- tx_
document_ ⚠to_ string - Returns the pretty-printed XML string for the document.
- tx_
document_ ⚠to_ string_ compact - Returns the compact XML string for the document.
- tx_
double_ ⚠attribute - Returns a double (f64) attribute value, or
default_valif the attribute does not exist or cannot be parsed. - tx_
element_ ⚠attribute - Returns the value of the named attribute on an element.
- tx_
element_ ⚠delete_ attribute - Deletes an attribute from an element by name.
- tx_
element_ ⚠get_ text - Returns the text content of an element’s first child text node.
- tx_
element_ ⚠name - Returns the tag name of an element node.
- tx_
element_ ⚠set_ attribute - Sets an attribute on an element. Creates the attribute if it doesn’t exist, or updates its value if it does.
- tx_
element_ ⚠set_ text - Sets the text content of an element.
- tx_
first_ ⚠child - Returns the first child of the given node, or
TX_NULL_NODEif none. - tx_
first_ ⚠child_ element - Returns the first child element, optionally filtered by tag name.
- tx_
insert_ ⚠after_ child - Inserts
childas the next sibling afterafter. - tx_
insert_ ⚠end_ child - Inserts
childas the last child ofparent. - tx_
insert_ ⚠first_ child - Inserts
childas the first child ofparent. - tx_
int_ ⚠attribute - Returns an integer attribute value, or
default_valif the attribute does not exist or cannot be parsed. - tx_
last_ ⚠child - Returns the last child of the given node, or
TX_NULL_NODEif none. - tx_
new_ ⚠comment - Creates a new comment node.
- tx_
new_ ⚠declaration - Creates a new declaration node.
- tx_
new_ ⚠element - Creates a new element node with the given tag name.
- tx_
new_ ⚠text - Creates a new text node with the given content.
- tx_
new_ ⚠unknown - Creates a new “unknown” node.
- tx_
next_ ⚠sibling - Returns the next sibling of the given node, or
TX_NULL_NODEif none. - tx_
next_ ⚠sibling_ element - Returns the next sibling element, optionally filtered by tag name.
- tx_
node_ is_ null - Returns
trueif the given node ID is the null sentinel. - tx_
node_ ⚠line - Returns the 1-based source line number where the node was parsed, or 0 if the node was not created by parsing.
- tx_
node_ ⚠type - Returns the type of the given node.
- tx_
node_ ⚠value - Returns the “value” of a node based on its type:
- tx_
parent ⚠ - Returns the parent of the given node, or
TX_NULL_NODEif none. - tx_
prev_ ⚠sibling - Returns the previous sibling of the given node, or
TX_NULL_NODEif none. - tx_
printer_ ⚠clear - Clears the printer output, resetting it to empty.
- tx_
printer_ ⚠close_ element - Closes the most recently opened element.
- tx_
printer_ ⚠free - Frees a printer previously created with
tx_printer_newortx_printer_new_compact. - tx_
printer_ new - Creates a new XML printer (pretty-print mode).
- tx_
printer_ new_ compact - Creates a new XML printer (compact mode, no whitespace).
- tx_
printer_ ⚠open_ element - Opens an element tag in the printer output.
- tx_
printer_ ⚠push_ attribute - Pushes an attribute onto the currently open element.
- tx_
printer_ ⚠push_ comment - Pushes a comment into the printer output.
- tx_
printer_ ⚠push_ text - Pushes text content into the current element.
- tx_
printer_ ⚠result - Returns the accumulated printer output as a C string.
- tx_
query_ ⚠bool_ attribute - Queries a boolean attribute value.
- tx_
query_ ⚠double_ attribute - Queries a double (f64) attribute value.
- tx_
query_ ⚠int_ attribute - Queries an integer attribute value.
- tx_
root_ ⚠element - Returns the root element of the document, or
TX_NULL_NODEif the document is empty.