axl main logo
 All Data Structures Functions Variables Typedefs Enumerations Enumerator Modules Pages
axl_bool axl_doc_iterate ( axlDoc doc,
AxlIterationMode  mode,
axlIterationFunc  func,
axlPointer  ptr 
)

Allows to perform an iteration over the documented provided, visiting all nodes inside it.

The function allows to configure the iteration module using AxlIterationMode (mode variable) and providing a callback function that will be called for each node found (axlIterationFunc).

The function, optionall, allows to provide a user pointer that will be passed to the callback function. See documentation for the callback and the iteration module for more details.

Here is an example:

1 void perform_iteration (axlDoc * doc)
2 {
3  // call to iterate
4  axl_doc_iterate (doc,
5  // visit childs before brothers
6  DEEP_ITERATION,
7  // the func to execute: see below
8  show_node_found,
9  // optional user pointer
10  NULL);
11 }
12 
13 axl_bool show_node_found (axlNode * node, axlNode * parent,
14  axlDoc * doc, axl_bool * was_removed,
15  axlPointer ptr)
16 {
17  // Show node found
18  printf ("Node found: %s\n", axl_node_get_name (node));
19 
20  // If the node is removed inside the iteration
21  // using axl_node_remove or axl_node_replace, you
22  // must notify the iteration system using was_removed
23  // as follow: (* was_removed) = axl_true;
24  //
25  // If you don't remove anything, you don't need to do
26  // anything especial with was_removed.
27 
28  // don't stop iteration
29  return axl_true;
30 }

See also alternative APIs:

Parameters
docThe xml document that will be iterated.
modeThe iterarion type to be performed.
funcThe function to be called for each node found.
ptrAn user defined pointer that will be passed to the callback function.
Returns
The function returns axl_true if the iteration was performed over all nodes or axl_false it it was stoped by the iteration function (by returning axl_false to stop the iteration). The function also axl_false if the parameters provided doc or func are not defined.

References axl_doc_get_root(), axl_false, and axl_return_val_if_fail.