- Main Page
- Namespaces
- Classes
- Files
- Related Pages

# /Users/fpy/titan-1-5-MBARI/Mers/Utils/Io/Xml/Dom/XMLLoader.cpp

    00001
    00002 //
    00003 // Copyright (c) 2005           Model-based Embedded and Robotic Systems Group
    00004 // All Rights Reserved          Massachusetts Institute of Technology
    00005 //
    00006 // This software is provided as is. Model-based Embedded and Robotic Systems
    00007 // (MERS) group does not assume any responsibility.
    00008 //
    00010
    00011 #include "XMLLoader.h"
    00012 #include "DOMUtils.h"
    00013 #include <Mers/Utils/Io/Xml/LoggingErrorHandler.h>
    00014 #include <Mers/Utils/Io/Xml/ScopedTranscoder.h>
    00015 #include <xercesc/util/XMLString.hpp>
    00016 #include <xercesc/dom/DOMError.hpp>
    00017 #include <xercesc/dom/DOMException.hpp>
    00018 #include <xercesc/sax/SAXParseException.hpp>
    00019 #include <xercesc/parsers/XercesDOMParser.hpp>
    00020 #include <memory>
    00021
    00023
    00024 using namespace Mers::Utils::Io::Xml::Dom;
    00025 using Mers::Utils::Io::Xml::CScopedTranscoder;
    00026 using Mers::Utils::Io::Xml::LoggingErrorHandler;
    00027 using XERCES_CPP_NAMESPACE::DOMDocument;
    00028 using XERCES_CPP_NAMESPACE::XMLException;
    00029 using XERCES_CPP_NAMESPACE::XMLString;
    00030 using XERCES_CPP_NAMESPACE::DOMError;
    00031 using XERCES_CPP_NAMESPACE::DOMException;
    00032 using XERCES_CPP_NAMESPACE::SAXParseException;
    00033 using XERCES_CPP_NAMESPACE::XercesDOMParser;
    00034 using std::auto_ptr;
    00035
    00037
    00038 Logger XMLLoader::s_logger
    00039 ( Logger::getInstance( "Mers.Utils.Io.Xml.Dom.XMLLoader" ) );
    00040
    00042
    00043 DOMDocument * XMLLoader::load( const char * fileName )
    00044 {
    00045         // Our parser
    00046         auto_ptr<XercesDOMParser> parser( NULL );
    00047         // The document we're loading.
    00048         DOMDocument * document = NULL;
    00049
    00050         // Load the XML file.
    00051         try {
    00052                 // Construct our parser.
    00053                 parser.reset( new XercesDOMParser() );
    00054
    00055                 // Use our Logging error handler.
    00056                 LoggingErrorHandler eHandler;
    00057                 parser->setErrorHandler( &eHandler );
    00058
    00059                 LOG4CPLUS_TRACE( s_logger, "Opening the file: " << fileName );
    00060
    00061                 // Parse the file.
    00062                 parser->parse( fileName );
    00063
    00064                 LOG4CPLUS_TRACE( s_logger, "Document has been loaded" );
    00065
    00066                 // Ok, the file is now loaded and parsed.  Lets get the DOMDocument.
    00067                 document = parser->adoptDocument();
    00068
    00069         } catch( const XMLException & toCatch ) {
    00070                 CScopedTranscoder message( toCatch.getMessage() );
    00071                 LOG4CPLUS_ERROR( s_logger, "XML Exception: " << message );
    00072         } catch( const DOMException & toCatch) {
    00073                 CScopedTranscoder message( toCatch.msg );
    00074                 LOG4CPLUS_ERROR( s_logger, "DOM Exception: " << message );
    00075         }
    00076
    00077         return document;
    00078 }
    00079