xmlReader.cc

Go to the documentation of this file.
00001 
00004 /* the present version relies on libxml++
00005 */
00006 
00007 /* Copyright (C) 2005 - 2006, Bernd Speiser */
00008 /* This file is part of BSUtilities.
00009 
00010 BSUtilities is free software; you can redistribute it and/or
00011 modify it under the terms of the GNU General Public License
00012 as published by the Free Software Foundation; either version 2
00013 of the License, or (at your option) any later version.
00014 
00015 BSUtilities is distributed in the hope that it will be useful,
00016 but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018 GNU General Public License for more details.
00019   
00020 You should have received a copy of the GNU General Public License
00021 along with this program; if not, write to the Free Software
00022 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
00023 02111-1307, USA.
00024 */
00025 
00026 
00027 #ifndef _xmlReader_cc
00028 #define _xmlReader_cc
00029 
00030 #include "xmlReader.h"
00031 
00032 #include <string>
00033 
00034 namespace BSUtilities {
00035   namespace xmlr {
00036 
00038   const std::string XmlReadError::XMLREADERROR 
00039                                   = "error while reading xml file!";
00040 
00042 
00048   TiXmlHandle xmlInit (const std::string &filename)
00049   {
00050      TiXmlDocument *doc = new TiXmlDocument(filename.c_str ());
00051 
00052      if (!doc || !doc->LoadFile ())
00053      {
00054        delete doc;
00055        throw XmlReadError ("xml file can not be loaded!");
00056      }
00057 
00058      return TiXmlHandle (doc->RootElement ());
00059   }
00060 
00062 
00067   void xmlFinish (TiXmlHandle &element)
00068   {
00069     if (TiXmlDocument *doc = (element.Element())->GetDocument ())
00070     {
00071       delete doc;
00072     }
00073   }
00074 
00075   } // end namespace xmlr
00076 }
00077 #endif /* _xmlReader_cc */

Generated on Sun Jul 26 16:51:58 2009 for BSUtilities by  doxygen 1.5.3