The mxmlWalkPrev and mxmlWalkNext functions can be used to iterate through the XML node tree:
mxml_node_t *node; node = mxmlWalkPrev(current, tree, MXML_DESCEND); node = mxmlWalkNext(current, tree, MXML_DESCEND);
In addition, you can find a named element/node using the mxmlFindElement function:
mxml_node_t *node; node = mxmlFindElement(tree, tree, "name", "attr", "value", MXML_DESCEND);
The name, attr, and value arguments can be passed as NULL to act as wildcards, e.g.:
/* Find the first "a" element */ node = mxmlFindElement(tree, tree, "a", NULL, NULL, MXML_DESCEND);
/* Find the first "a" element with "href" attribute */ node = mxmlFindElement(tree, tree, "a", "href", NULL, MXML_DESCEND);
/* Find the first "a" element with "href" to a URL */ node = mxmlFindElement(tree, tree, "a", "href", "http://www.easysw.com/", MXML_DESCEND);
/* Find the first element with a "src" attribute */ node = mxmlFindElement(tree, tree, NULL, "src", NULL, MXML_DESCEND);
/* Find the first element with a "src" = "foo.jpg" */ node = mxmlFindElement(tree, tree, NULL, "src", "foo.jpg", MXML_DESCEND);
You can also iterate with the same function:
mxml_node_t *node; for (node = mxmlFindElement(tree, tree, "name", NULL, NULL, MXML_DESCEND); node != NULL; node = mxmlFindElement(node, tree, "name", NULL, NULL, MXML_DESCEND)) { ... do something ... }
The MXML_DESCEND argument can actually be one of three constants:
The previous node from "group" would be the "node" element to the
left, while the next node from "group" would be the "node" element to
the right.
This mode is only applicable to the search function; the walk
functions treat this as MXML_DESCEND since every call is a
first time.
If you were to walk from the root node "?xml" to the end of the tree with mxmlWalkNext(), the order would be:
?xml data node val1 node val2 node val3 group node val4 node val5 node val6 node val7 node val8
If you started at "val8" and walked using mxmlWalkPrev(), the order would be reversed, ending at "?xml".