[Opensrf-commits] r1927 - in trunk: include/opensrf src/libopensrf (scottmk)

svn at svn.open-ils.org svn at svn.open-ils.org
Sun Feb 14 21:48:50 EST 2010


Author: scottmk
Date: 2010-02-14 21:48:49 -0500 (Sun, 14 Feb 2010)
New Revision: 1927

Modified:
   trunk/include/opensrf/xml_utils.h
   trunk/src/libopensrf/xml_utils.c
Log:
1. Change xmlSaxAttr() to return const char* instead of
non-const char*.

2. Add some doxygen-style comments.

3. Tidy up the white space here and there.

M    include/opensrf/xml_utils.h
M    src/libopensrf/xml_utils.c


Modified: trunk/include/opensrf/xml_utils.h
===================================================================
--- trunk/include/opensrf/xml_utils.h	2010-02-10 21:14:43 UTC (rev 1926)
+++ trunk/include/opensrf/xml_utils.h	2010-02-15 02:48:49 UTC (rev 1927)
@@ -26,7 +26,7 @@
 /* Takes an xmlChar** from a SAX callback and returns the value
 	for the attribute with name 'name'
 	*/
-char* xmlSaxAttr( const xmlChar** atts, const char* name ); 
+const char* xmlSaxAttr( const xmlChar** atts, const char* name ); 
 
 /**
   Sets the xml attributes from atts to the given dom node 

Modified: trunk/src/libopensrf/xml_utils.c
===================================================================
--- trunk/src/libopensrf/xml_utils.c	2010-02-10 21:14:43 UTC (rev 1926)
+++ trunk/src/libopensrf/xml_utils.c	2010-02-15 02:48:49 UTC (rev 1927)
@@ -3,6 +3,13 @@
 /* helper function */
 static jsonObject* _xmlToJSON(xmlNodePtr node, jsonObject*);
 
+/**
+	@brief Write then contents of an xmlNode to standard output.
+	@param node Pointer to an xmlNode
+
+	Write the text content of an xmlNode, and all its dependent nodes recursively, to
+	standard output.
+*/
 void recurse_doc( xmlNodePtr node ) {
 	if( node == NULL ) return;
 	printf("Recurse: %s =>  %s", node->name, node->content );
@@ -13,8 +20,6 @@
 	}
 }
 
-
-
 jsonObject* xmlDocToJSON(xmlDocPtr doc) {
 	if(!doc) return NULL;
 	return _xmlToJSON(xmlDocGetRootElement(doc), NULL);
@@ -27,7 +32,7 @@
 	if(obj == NULL) obj = jsonNewObject(NULL);
 
 	if(node->type == XML_TEXT_NODE) {
-		jsonObjectSetString(obj, (char*) node->content);	
+		jsonObjectSetString(obj, (char*) node->content);
 
 	} else if(node->type == XML_ELEMENT_NODE || node->type == XML_ATTRIBUTE_NODE ) {
 
@@ -50,7 +55,7 @@
 		}
 
 		xmlNodePtr child = node->children;
-                if (child) { // at least one...
+		if (child) { // at least one...
 			if (child != node->last) { // more than one -- ignore TEXT nodes
 				while(child) {
 					if (child->type != XML_TEXT_NODE) _xmlToJSON(child, new_obj);
@@ -59,8 +64,8 @@
 			} else {
 				_xmlToJSON(child, new_obj);
 			}
-                }
-	}	
+		}
+	}
 
 	return obj;
 }
@@ -92,22 +97,48 @@
 	}
 }
 
+/**
+	@brief Search for the value of a given attribute in an attribute array.
+	@param atts Pointer to the attribute array to be searched.
+	@param atts Pointer to the attribute name to be sought.
+	@return A pointer to the attribute value if found, or NULL if not.
 
+	The @a atts parameter points to a ragged array of strings.  The @a atts[0] pointer points
+	to an attribute name, and @a atts[1] points to the corresponding attribute value.  The
+	remaining pointers likewise point alternately to names and values.  The end of the
+	list is marked by a NULL.
 
+	In practice, the @a atts array is constructed by the XML parser and passed to a callback
+	function.
 
-char* xmlSaxAttr( const xmlChar** atts, const char* name ) {
+*/
+const char* xmlSaxAttr( const xmlChar** atts, const char* name ) {
 	if( atts && name ) {
 		int i;
 		for(i = 0; (atts[i] != NULL); i++) {
 			if(!strcmp((char*) atts[i], name)) {
-				if(atts[++i]) return (char*) atts[i];
+				if(atts[++i])
+					return (const char*) atts[i];
 			}
 		}
 	}
 	return NULL;
 }
 
+/**
+	@brief Add a series of attributes to an xmlNode.
+	@param node Pointer to the xmlNode to which the attributes will be added.
+	@param atts Pointer to the attributes to be added.
+	@return Zero in all cases.
 
+	The @a atts parameter points to a ragged array of strings.  The @a atts[0] pointer points
+	to an attribute name, and @a atts[1] points to the corresponding attribute value.  The
+	remaining pointers likewise point alternately to names and values.  The end of the
+	list is marked by a NULL.
+
+	In practice, the @a atts array is constructed by the XML parser and passed to a callback
+	function.
+*/
 int xmlAddAttrs( xmlNodePtr node, const xmlChar** atts ) {
 	if( node && atts ) {
 		int i;



More information about the opensrf-commits mailing list