CLAM-Development
1.1
|
00001 /* 00002 * Copyright (c) 2001-2004 MUSIC TECHNOLOGY GROUP (MTG) 00003 * UNIVERSITAT POMPEU FABRA 00004 * 00005 * 00006 * This program is free software; you can redistribute it and/or modify 00007 * it under the terms of the GNU General Public License as published by 00008 * the Free Software Foundation; either version 2 of the License, or 00009 * (at your option) any later version. 00010 * 00011 * This program is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 * GNU General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU General Public License 00017 * along with this program; if not, write to the Free Software 00018 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00019 * 00020 */ 00021 #ifndef LibXmlDomReader_hxx 00022 #define LibXmlDomReader_hxx 00023 00024 #include "XmlStorageErr.hxx" 00025 00026 #include <string> 00027 #include <list> 00028 #include <sstream> 00029 #include "Assert.hxx" 00030 #include <libxml++/parsers/domparser.h> 00031 00032 namespace CLAM 00033 { 00034 00039 class LibXmlDomReader 00040 { 00041 xmlpp::DomParser * parser; 00042 public: 00043 LibXmlDomReader() 00044 { 00045 // TODO: This is a hack for xerces bug on adoptNode, parser should be local variable 00046 // This should be done in the read method itself when the xerces but is solved 00047 parser = new xmlpp::DomParser; 00048 } 00049 ~LibXmlDomReader() 00050 { 00051 // TODO: This is a hack for xerces bug on adoptNode, parser should be local variable 00052 if (parser) delete parser; 00053 } 00054 // TODO: This is a hack parser should be local variable 00055 xmlpp::DomParser * adoptParser() 00056 { 00057 xmlpp::DomParser * temp = parser; 00058 parser = 0; 00059 return temp; 00060 } 00061 xmlpp::Document * read(std::istream & target) 00062 { 00063 if (target.fail()) throw XmlStorageErr("Unable to open the document source"); 00064 parser->set_validate(false); 00065 parser->set_substitute_entities(); 00066 try 00067 { 00068 parser->parse_stream(target); 00069 } 00070 catch (xmlpp::parse_error & e) 00071 { 00072 throw XmlStorageErr( 00073 std::string("\nXML Parser Errors:\n")+e.what()+"\n"); 00074 } 00075 xmlpp::Document *doc = parser->get_document(); 00076 CLAM_ASSERT(doc,"No errors but document not loaded!"); 00077 return doc; 00078 } 00079 }; 00080 00081 00082 00083 } 00084 #endif//LibXmlDomReader_hxx 00085