diff options
Diffstat (limited to 'xml-parser.c')
| -rw-r--r-- | xml-parser.c | 76 |
1 files changed, 38 insertions, 38 deletions
diff --git a/xml-parser.c b/xml-parser.c index 444ea58..2b3005a 100644 --- a/xml-parser.c +++ b/xml-parser.c @@ -1,16 +1,16 @@ /* Cataract - Static web photo gallery generator * Copyright (C) 2008 Tomas Bzatek <tbzatek@users.sourceforge.net> - * + * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. @@ -33,13 +33,13 @@ /* - * xml_parser_load: initialize and load the XML document - */ + * xml_parser_load: initialize and load the XML document + */ TXMLFile * xml_parser_load (const char *filename) { TXMLFile *file; - + file = malloc (sizeof (TXMLFile)); memset (file, 0, sizeof (TXMLFile)); @@ -55,24 +55,24 @@ xml_parser_load (const char *filename) file->xpathCtx = xmlXPathNewContext (file->doc); if (file->xpathCtx == NULL) { fprintf (stderr, "Error: unable to create new XPath context\n"); - xmlFreeDoc (file->doc); + xmlFreeDoc (file->doc); free (file); return FALSE; } - return file; + return file; } /* - * xml_parser_close: close the XML document parser - */ -void + * xml_parser_close: close the XML document parser + */ +void xml_parser_close (TXMLFile *file) { if (file) { - xmlXPathFreeContext (file->xpathCtx); + xmlXPathFreeContext (file->xpathCtx); xmlFreeDoc (file->doc); free (file); file = NULL; @@ -82,13 +82,13 @@ xml_parser_close (TXMLFile *file) /* * xml_file_get_node_value: retrieve string value from XPath node - * - multiple matched nodes will be concatenated into one string - * - otherwise please use [0], [1] etc. quantificators + * - multiple matched nodes will be concatenated into one string + * - otherwise please use [0], [1] etc. quantificators */ -char * +char * xml_file_get_node_value (TXMLFile *file, const char *x_path) { - xmlXPathObjectPtr xpathObj; + xmlXPathObjectPtr xpathObj; xmlNodePtr cur; char *val, *valx; int i; @@ -108,13 +108,13 @@ xml_file_get_node_value (TXMLFile *file, const char *x_path) #ifdef __DEBUG_ALL__ printf("Result (%d nodes):\n", xpathObj->nodesetval->nodeNr); #endif - + for (i = 0; i < xpathObj->nodesetval->nodeNr; i++) { cur = xpathObj->nodesetval->nodeTab[i]; #ifdef __DEBUG_ALL__ printf(" XPATH matched: element node \"%s[%d]\", value = '%s'\n", cur->name, i, cur->content); - #endif + #endif if (cur->content) { @@ -131,19 +131,19 @@ xml_file_get_node_value (TXMLFile *file, const char *x_path) } } } - + xmlXPathFreeObject (xpathObj); - return val; + return val; } /* * xml_file_get_node_attribute: retrieve attribute value from XPath node */ -char * +char * xml_file_get_node_attribute (TXMLFile *file, const char *x_path, const char *attr) { - xmlXPathObjectPtr xpathObj; + xmlXPathObjectPtr xpathObj; xmlNodePtr cur; xmlChar *attrvx; char *attrv; @@ -157,7 +157,7 @@ xml_file_get_node_attribute (TXMLFile *file, const char *x_path, const char *att fprintf (stderr, "Error: unable to evaluate xpath expression \"%s\"\n", x_path); return NULL; } - + attrv = NULL; if ((xpathObj->nodesetval) && (xpathObj->nodesetval->nodeNr > 0)) { cur = xpathObj->nodesetval->nodeTab[0]; @@ -165,28 +165,28 @@ xml_file_get_node_attribute (TXMLFile *file, const char *x_path, const char *att if (attrvx) { attrv = strdup ((char*) attrvx); xmlFree (attrvx); - } + } #ifdef __DEBUG_ALL__ printf("Result (%d nodes):\n", xpathObj->nodesetval->nodeNr); printf(" XPATH matched: element node \"%s\", value = '%s', property value = '%s'\n", cur->name, cur->content, attrv); - #endif + #endif } - + xmlXPathFreeObject (xpathObj); - return attrv; + return attrv; } -long +long xml_file_get_node_attribute_long (TXMLFile *file, const char *x_path, const char *attr, const int _default) { char *s; long int i; - + s = xml_file_get_node_attribute (file, x_path, attr); if (s == NULL) return _default; - + i = atol (s); free (s); return i; @@ -195,25 +195,25 @@ xml_file_get_node_attribute_long (TXMLFile *file, const char *x_path, const char /* * xml_file_get_node_present: existency test of the XPath node */ -gboolean +gboolean xml_file_get_node_present (TXMLFile *file, const char *x_path) { - return xml_file_node_get_children_count (file, x_path) > 0; + return xml_file_node_get_children_count (file, x_path) > 0; } /* * xml_file_node_get_children_count: retrieve number of children items of the specified XPath node */ -int +int xml_file_node_get_children_count (TXMLFile *file, const char *x_path) { - xmlXPathObjectPtr xpathObj; + xmlXPathObjectPtr xpathObj; int count; - + if ((! file) || (! x_path)) return 0; - + /* Evaluate xpath expression */ xpathObj = xmlXPathEvalExpression ((const xmlChar *) x_path, file->xpathCtx); if (xpathObj == NULL) { @@ -224,7 +224,7 @@ xml_file_node_get_children_count (TXMLFile *file, const char *x_path) count = 0; if (xpathObj->nodesetval) count = xpathObj->nodesetval->nodeNr; - + xmlXPathFreeObject (xpathObj); - return count; + return count; } |
