- Main Page
- Namespaces
- Classes
- Files

- Search for |

# xml_parser.cpp

    00001 // "xml_parser.h"
    00002
    00003 // (c) OPAC Team, LIFL, August 2005
    00004
    00005 /*
    00006    Contact: paradiseo-help@lists.gforge.inria.fr
    00007 */
    00008
    00009 #include <libxml/xmlreader.h>
    00010
    00011 #include "xml_parser.h"
    00012
    00013 static xmlTextReaderPtr reader;
    00014
    00015 void openXMLDocument (const char * __filename) {
    00016
    00017   reader = xmlNewTextReaderFilename (__filename);
    00018
    00019   if (! reader) {
    00020
    00021     fprintf (stderr, "unable to open '%s'.\n", __filename);
    00022     exit (1);
    00023   }
    00024 }
    00025
    00026 void closeXMLDocument () {
    00027
    00028   xmlFreeTextReader (reader);
    00029 }
    00030
    00031 std :: string getAttributeValue (const std :: string & __attr) {
    00032
    00033   xmlChar * value = xmlTextReaderGetAttribute (reader, (const xmlChar *) __attr.c_str ());
    00034
    00035   std :: string str ((const char *) value);
    00036
    00037   xmlFree (value);
    00038
    00039   return str;
    00040 }
    00041
    00042 static bool isSep (const xmlChar * __text) {
    00043
    00044   for (unsigned i = 0; i < strlen ((char *) __text); i ++)
    00045     if (__text [i] != ' ' && __text [i] != '\t' && __text [i] != '\n')
    00046       return false;
    00047   return true;
    00048 }
    00049
    00050 std :: string getNextNode () {
    00051
    00052   xmlChar * name, * value;
    00053
    00054   do {
    00055     xmlTextReaderRead (reader);
    00056     name = xmlTextReaderName (reader);
    00057     value = xmlTextReaderValue (reader);
    00058     //    printf ("value = %s\n", value);
    00059   } while (! strcmp ((char *) name, "#text") && isSep (value));
    00060
    00061   std :: string str;
    00062
    00063   if (strcmp ((char *) name, "#text"))
    00064     str.assign ((char *) name);
    00065   else
    00066     str.assign ((char *) value);
    00067
    00068   if (name)
    00069     xmlFree (name);
    00070   if (value)
    00071     xmlFree (value);
    00072
    00073   return str;
    00074 }
    00075