10#include "GaudiKernel/MsgStream.h"
12#include "xercesc/util/PlatformUtils.hpp"
13#include "xercesc/util/XMLException.hpp"
14#include <xercesc/dom/DOM.hpp>
15#include <xercesc/framework/StdOutFormatTarget.hpp>
16#include <xercesc/framework/LocalFileFormatTarget.hpp>
17#include <xercesc/framework/MemBufInputSource.hpp>
18#include <xercesc/parsers/XercesDOMParser.hpp>
19#include <xercesc/util/XMLUni.hpp>
20#include <xercesc/util/OutOfMemoryException.hpp>
24using namespace xercesc;
47 bool errorsOccured =
false;
52 log<<MSG::WARNING<<
"ParseFile() - something wrong, could not find XML file "<<s<<
endmsg;
63 catch (
const OutOfMemoryException&)
65 XERCES_STD_QUALIFIER cerr <<
"OutOfMemoryException" << XERCES_STD_QUALIFIER endl;
68 catch (
const XMLException& e)
70 XERCES_STD_QUALIFIER cerr <<
"An error occurred during parsing\n Message: "
71 << XMLString::transcode(e.getMessage()) << XERCES_STD_QUALIFIER endl;
74 catch (
const DOMException& e)
76 const unsigned int maxChars = 2047;
77 XMLCh errText[maxChars + 1];
79 XERCES_STD_QUALIFIER cerr <<
"\nDOM Error during parsing: '" << s <<
"'\n"
80 <<
"DOMException code is: " << e.code << XERCES_STD_QUALIFIER endl;
82 if (DOMImplementation::loadDOMExceptionMsg(e.code, errText, maxChars))
83 XERCES_STD_QUALIFIER cerr <<
"Message is: " << XMLString::transcode(errText) << XERCES_STD_QUALIFIER endl;
89 XERCES_STD_QUALIFIER cerr <<
"An error occurred during parsing\n " << XERCES_STD_QUALIFIER endl;
101 if (errorOccured)
return false;
107 const char*
str=s.c_str();
108 MemBufInputSource memBuf (
reinterpret_cast<const XMLByte*
>(
str),strlen(
str),
"prodInfo",
false);
110 bool errorsOccured =
false;
116 catch (
const OutOfMemoryException&)
118 XERCES_STD_QUALIFIER cerr <<
"OutOfMemoryException" << XERCES_STD_QUALIFIER endl;
119 errorsOccured =
true;
121 catch (
const XMLException& e)
123 XERCES_STD_QUALIFIER cerr <<
"An error occurred during parsing\n Message: "
124 << XMLString::transcode(e.getMessage()) << XERCES_STD_QUALIFIER endl;
125 errorsOccured =
true;
127 catch (
const DOMException& e)
129 const unsigned int maxChars = 2047;
130 XMLCh errText[maxChars + 1];
132 XERCES_STD_QUALIFIER cerr <<
"\nDOM Error during parsing: '" << s <<
"'\n"
133 <<
"DOMException code is: " << e.code << XERCES_STD_QUALIFIER endl;
135 if (DOMImplementation::loadDOMExceptionMsg(e.code, errText, maxChars))
136 XERCES_STD_QUALIFIER cerr <<
"Message is: " << XMLString::transcode(errText) << XERCES_STD_QUALIFIER endl;
138 errorsOccured =
true;
142 XERCES_STD_QUALIFIER cerr <<
"An error occurred during parsing\n " << XERCES_STD_QUALIFIER endl;
143 errorsOccured =
true;
146 return errorsOccured;
149 const std::string& s)
159 XMLString::transcode(
"LS 3.0 Core 2.0", tempStr, 99);
160 DOMImplementation* implementation = DOMImplementationRegistry::getDOMImplementation(tempStr);
161 DOMLSSerializer* serializer =
static_cast<DOMImplementationLS*
>(implementation)->createLSSerializer();
165 XMLFormatTarget* target =
new LocalFileFormatTarget(s.c_str());
166 DOMLSOutput* domoutput =
static_cast<DOMImplementationLS*
>(implementation)->createLSOutput();
168 if(
m_doc->getDOMConfig()->canSetParameter(XMLUni::fgDOMComments,
true) )
m_doc->getDOMConfig()->setParameter(XMLUni::fgDOMComments,
false);
169 m_doc->normalizeDocument();
171 domoutput->setByteStream(target);
172 serializer->write(
m_doc, domoutput);
173 domoutput->release();
174 serializer->release();
184 log<<MSG::WARNING<<
"navigateTree() - something is wrong! no document set! doing nothing!"<<
endmsg;
188 node =
dynamic_cast<DOMNode*
>(
m_doc->getDocumentElement());
189 if( !
node ) std::abort();
200 log<<MSG::WARNING<<
"Calling elementLoop() with NULL pointer!!!"<<
endmsg;
203 if (!(
e->getNodeType()==DOMNode::ELEMENT_NODE))
return;
204 XMLHandler *
h =
m_xs.GetHandler(e);
209 stopLoop=
h->IsLoopToBeStopped();
215 char*
name=XMLString::transcode(
e->getNodeName());
217 XMLString::release(&name);
218 for (child=
e->getFirstChild();child!=0;child=child->getNextSibling())
220 if (child->getNodeType()==DOMNode::ELEMENT_NODE) {
230 XMLPlatformUtils::Initialize();
233 catch(
const XMLException &toCatch) {
234 XERCES_STD_QUALIFIER cerr <<
"Error during Xerces-c Initialization.\n"
235 <<
" Exception message:"
236 << XERCES_STD_QUALIFIER endl;
245 XMLPlatformUtils::Terminate();
static std::string find_file(const std::string &logical_file_name, const std::string &search_path)
virtual bool ParseString(const std::string &) override
virtual void elementLoop() override
virtual bool WriteToFile(const std::string &) override
virtual bool ParseFile(const std::string &) override
virtual bool ParseFileAndNavigate(AGDDController &c, const std::string &) override
xercesc::XercesDOMParser * m_parser
xercesc::DOMDocument * m_doc
virtual void navigateTree(AGDDController &c) override
XercesParser(XMLHandlerStore &xs)
virtual bool ParseStringAndNavigate(AGDDController &c, const std::string &) override
singleton-like access to IMessageSvc via open function and helper
IMessageSvc * getMessageSvc(bool quiet=false)