From 72f8877d57343fbc2bb42785da9d0c26bd3f0d7a Mon Sep 17 00:00:00 2001 From: Benny Prijono Date: Mon, 1 Jun 2009 09:28:28 +0000 Subject: Ticket #868: Added functions to search XML child nodes recursively git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@2727 74dad513-b988-da41-8d7b-12977e46ad98 --- pjlib-util/include/pjlib-util/xml.h | 57 +++++++++++++++++++++++++++++++------ 1 file changed, 48 insertions(+), 9 deletions(-) (limited to 'pjlib-util/include') diff --git a/pjlib-util/include/pjlib-util/xml.h b/pjlib-util/include/pjlib-util/xml.h index 5595c20c..9188ae6b 100644 --- a/pjlib-util/include/pjlib-util/xml.h +++ b/pjlib-util/include/pjlib-util/xml.h @@ -149,17 +149,18 @@ PJ_DECL(void) pj_xml_add_node( pj_xml_node *parent, pj_xml_node *node ); PJ_DECL(void) pj_xml_add_attr( pj_xml_node *node, pj_xml_attr *attr ); /** - * Find first node with the specified name. + * Find first direct child node with the specified name. * * @param parent Parent node. * @param name Node name to find. * * @return XML node found or NULL. */ -PJ_DECL(pj_xml_node*) pj_xml_find_node(pj_xml_node *parent, const pj_str_t *name); +PJ_DECL(pj_xml_node*) pj_xml_find_node(const pj_xml_node *parent, + const pj_str_t *name); /** - * Find first node with the specified name. + * Find next direct child node with the specified name. * * @param parent Parent node. * @param node node->next is the starting point. @@ -167,11 +168,26 @@ PJ_DECL(pj_xml_node*) pj_xml_find_node(pj_xml_node *parent, const pj_str_t *name * * @return XML node found or NULL. */ -PJ_DECL(pj_xml_node*) pj_xml_find_next_node(pj_xml_node *parent, pj_xml_node *node, +PJ_DECL(pj_xml_node*) pj_xml_find_next_node(const pj_xml_node *parent, + const pj_xml_node *node, const pj_str_t *name); /** - * Find first attribute within a node with the specified name and optional value. + * Recursively find the first node with the specified name in the child nodes + * and their children. + * + * @param parent Parent node. + * @param name Node name to find. + * + * @return XML node found or NULL. + */ +PJ_DECL(pj_xml_node*) pj_xml_find_node_rec(const pj_xml_node *parent, + const pj_str_t *name); + + +/** + * Find first attribute within a node with the specified name and optional + * value. * * @param node XML Node. * @param name Attribute name to find. @@ -179,7 +195,8 @@ PJ_DECL(pj_xml_node*) pj_xml_find_next_node(pj_xml_node *parent, pj_xml_node *no * * @return XML attribute found, or NULL. */ -PJ_DECL(pj_xml_attr*) pj_xml_find_attr(pj_xml_node *node, const pj_str_t *name, +PJ_DECL(pj_xml_attr*) pj_xml_find_attr(const pj_xml_node *node, + const pj_str_t *name, const pj_str_t *value); @@ -187,15 +204,37 @@ PJ_DECL(pj_xml_attr*) pj_xml_find_attr(pj_xml_node *node, const pj_str_t *name, * Find a direct child node with the specified name and match the function. * * @param parent Parent node. - * @param name Optional name. + * @param name Optional name. If this is NULL, the name will not be + * matched. * @param data Data to be passed to matching function. * @param match Optional matching function. * * @return The first matched node, or NULL. */ -PJ_DECL(pj_xml_node*) pj_xml_find( pj_xml_node *parent, const pj_str_t *name, +PJ_DECL(pj_xml_node*) pj_xml_find( const pj_xml_node *parent, + const pj_str_t *name, const void *data, - pj_bool_t (*match)(pj_xml_node *, const void*)); + pj_bool_t (*match)(const pj_xml_node *, + const void*)); + + +/** + * Recursively find a child node with the specified name and match the + * function. + * + * @param parent Parent node. + * @param name Optional name. If this is NULL, the name will not be + * matched. + * @param data Data to be passed to matching function. + * @param match Optional matching function. + * + * @return The first matched node, or NULL. + */ +PJ_DECL(pj_xml_node*) pj_xml_find_rec(const pj_xml_node *parent, + const pj_str_t *name, + const void *data, + pj_bool_t (*match)(const pj_xml_node*, + const void*)); /** -- cgit v1.2.3