/*
Copyright Universite de Versailles Saint-Quentin en Yvelines 2009
AUTHORS: Sebastien Briais, Sid Touati
This file is part of GDD.
GDD is free software: you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
GDD 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with GDD. If not, see
.
*/
/** This file is only used internally. So it does not pollute namespace. */
#ifndef __XMLUTIL_H
#define __XMLUTIL_H
#include
#include
#include
#include
#include
#include
#define char_of_xmlchar(s) ((char *)(s))
#define xmlchar_of_char(s) ((xmlChar *)(s))
/** sax read function for file streams */
static int sax_read(void *stream, char *buf, int len) {
return fread(buf, 1, len, (FILE *)stream);
}
/** sax close function for file streams */
static int sax_close(void *stream) {
// return fclose((FILE *)stream);
return 0;
}
/** find the value of an optionnal attribute in an array of attributes
@param[in] attr = attribute to find
@param[in] attrs = array of attributes as given by sax parser
@return the index of the value in attrs or -1 if not found */
static int findOptAttr(const char *attr, const xmlChar **attrs) {
int i;
for(i = 0; attrs[i] != NULL; i+=2) {
if(xmlStrEqual(attrs[i], xmlchar_of_char(attr))) {
return (i+1);
}
}
return -1;
}
/** find the value of an attribute in an array of attributes or fail
@param[in] attr = attribute to find
@param[in] attrs = array of attributes as given by sax parser
@return the index of the value in attrs or fail if not found */
static int findAttr(const char *attr, const xmlChar **attrs) {
int ret = findOptAttr(attr, attrs);
if(ret == -1) {
fprintf(stderr,"attribute %s not found\n",attr);
exit(1);
}
return ret;
}
/** get the integer value of an xml string
@param[in] str = xml string
@return the integer value */
static int atoi_xml(const xmlChar *str) {
return atoi(char_of_xmlchar(str));
}
#endif