[Compbench-devel] CompBenchmarks++/libcompbenchmarks/Base XMLReader.cpp, NONE, 1.1 XMLReader.h, NON
Brought to you by:
xfred
From: Frederic T. <xf...@us...> - 2007-01-23 18:43:51
|
Update of /cvsroot/compbench/CompBenchmarks++/libcompbenchmarks/Base In directory sc8-pr-cvs4.sourceforge.net:/tmp/cvs-serv1074 Added Files: XMLReader.cpp XMLReader.h Log Message: First import. --- NEW FILE: XMLReader.cpp --- #include <Base/XMLReader.h> #include <Base/XML.h> #include <System/System.h> using namespace CBM; XMLReader::XMLReader() { } XMLNode *XMLReader::parse(xmlNode *node, XMLNode **C) { xmlNode *cur_n; xmlAttr *cur_a; XMLNode *N; XMLAttribute *A; std::string tmp_a; std::string tmp_n; std::string tmp_v; xmlChar *tmpcat_n; xmlChar *buffer; for(cur_n=node; cur_n; cur_n=cur_n->next) { if (cur_n->type == XML_TEXT_NODE) { if (*C) { tmpcat_n=xmlStrdup(cur_n->content); if (tmpcat_n) { tmp_v=(char*) tmpcat_n; xmlFree(tmpcat_n); cbmSystem->Chomp(tmp_v); if (tmp_v!="") (*C)->append(tmp_v); } } } if (cur_n->type == XML_ELEMENT_NODE) { tmpcat_n=0; tmp_n=""; cbmSystem->Chomp(tmp_n); N=new CBM::XMLNode((char*) cur_n->name, tmp_n); if (!*(C)) { *C=N; } else { (*C)->add(N); } for(cur_a=cur_n->properties; cur_a; cur_a=cur_a->next) { tmp_a=(char*) xmlGetProp(cur_n, cur_a->name); cbmSystem->Chomp(tmp_a); A=new CBM::XMLAttribute((char*) cur_a->name, tmp_a); N->add(A); } parse(cur_n->children, &N); } } if (C) return(*C); else return(0); } XMLNode *XMLReader::read(std::string filename) { xmlDoc *doc; xmlNode *root; XMLNode *C = 0; xmlInitParser(); LIBXML_TEST_VERSION doc=xmlReadFile(filename.c_str(), NULL, 0); if (!doc) return(0); root=xmlDocGetRootElement(doc); parse(root, &C); xmlCleanupParser(); xmlMemoryDump(); return(C); } XMLReader::~XMLReader() { } --- NEW FILE: XMLReader.h --- /* ---------------------------------------------------------------------------- $Id: XMLReader.h,v 1.1 2007/01/23 18:43:45 xfred Exp $ This is free software. For details, see the GNU Public License in the COPYING file, or Look http://www.fsf.org ------------------------------------------------------------------------- */ #ifndef H_XMLREADER #define H_XMLREADER 1 #include <string> #include <libxml/tree.h> #include <libxml/parser.h> namespace CBM { /** \brief XML file reader * Class to read XML files and build an XMLNode. * \sa XMLNode */ class XMLReader { protected: virtual class XMLNode *parse(xmlNode *node, class XMLNode **C); public: /** Constructor */ XMLReader(); /** Parse a file Transform given XML file to and XMLNode representation. \param filename filename to read \return XMLNode instance (hierarchy) \sa XMLNode */ class XMLNode *read(std::string filename); /** Destructor */ virtual ~XMLReader(); }; } #endif |