Skip to main content

Crate tinyxml2_capi

Crate tinyxml2_capi 

Source
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 Document for FFI use.
TxNodeId
A C-compatible node identifier.
TxPrinter
Opaque wrapper around an XmlPrinter for FFI use.

Enums§

TxError
C-compatible error code enum matching TinyXML2 error values.
TxNodeType
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_val if the attribute does not exist or cannot be parsed.
tx_delete_child
Deletes child from parent.
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_val if 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_NODE if none.
tx_first_child_element
Returns the first child element, optionally filtered by tag name.
tx_insert_after_child
Inserts child as the next sibling after after.
tx_insert_end_child
Inserts child as the last child of parent.
tx_insert_first_child
Inserts child as the first child of parent.
tx_int_attribute
Returns an integer attribute value, or default_val if the attribute does not exist or cannot be parsed.
tx_last_child
Returns the last child of the given node, or TX_NULL_NODE if 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_NODE if none.
tx_next_sibling_element
Returns the next sibling element, optionally filtered by tag name.
tx_node_is_null
Returns true if 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_NODE if none.
tx_prev_sibling
Returns the previous sibling of the given node, or TX_NULL_NODE if 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_new or tx_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_NODE if the document is empty.