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;
45 bool errorsOccured =
false;
50 log<<MSG::WARNING<<
"ParseFile() - something wrong, could not find XML file "<<s<<
endmsg;
56 m_parser = std::make_unique<XercesDOMParser>();
61 catch (
const OutOfMemoryException&)
63 XERCES_STD_QUALIFIER cerr <<
"OutOfMemoryException" << XERCES_STD_QUALIFIER endl;
66 catch (
const XMLException& e)
68 XERCES_STD_QUALIFIER cerr <<
"An error occurred during parsing\n Message: "
69 << XMLString::transcode(e.getMessage()) << XERCES_STD_QUALIFIER endl;
72 catch (
const DOMException& e)
74 const unsigned int maxChars = 2047;
75 XMLCh errText[maxChars + 1];
77 XERCES_STD_QUALIFIER cerr <<
"\nDOM Error during parsing: '" << s <<
"'\n"
78 <<
"DOMException code is: " << e.code << XERCES_STD_QUALIFIER endl;
80 if (DOMImplementation::loadDOMExceptionMsg(e.code, errText, maxChars))
81 XERCES_STD_QUALIFIER cerr <<
"Message is: " << XMLString::transcode(errText) << XERCES_STD_QUALIFIER endl;
87 XERCES_STD_QUALIFIER cerr <<
"An error occurred during parsing\n " << XERCES_STD_QUALIFIER endl;
99 if (errorOccured)
return false;
105 const char*
str=s.c_str();
106 MemBufInputSource memBuf (
reinterpret_cast<const XMLByte*
>(
str),strlen(
str),
"prodInfo",
false);
107 m_parser = std::make_unique<XercesDOMParser>();
108 bool errorsOccured =
false;
114 catch (
const OutOfMemoryException&)
116 XERCES_STD_QUALIFIER cerr <<
"OutOfMemoryException" << XERCES_STD_QUALIFIER endl;
117 errorsOccured =
true;
119 catch (
const XMLException& e)
121 XERCES_STD_QUALIFIER cerr <<
"An error occurred during parsing\n Message: "
122 << XMLString::transcode(e.getMessage()) << XERCES_STD_QUALIFIER endl;
123 errorsOccured =
true;
125 catch (
const DOMException& e)
127 const unsigned int maxChars = 2047;
128 XMLCh errText[maxChars + 1];
130 XERCES_STD_QUALIFIER cerr <<
"\nDOM Error during parsing: '" << s <<
"'\n"
131 <<
"DOMException code is: " << e.code << XERCES_STD_QUALIFIER endl;
133 if (DOMImplementation::loadDOMExceptionMsg(e.code, errText, maxChars))
134 XERCES_STD_QUALIFIER cerr <<
"Message is: " << XMLString::transcode(errText) << XERCES_STD_QUALIFIER endl;
136 errorsOccured =
true;
140 XERCES_STD_QUALIFIER cerr <<
"An error occurred during parsing\n " << XERCES_STD_QUALIFIER endl;
141 errorsOccured =
true;
144 return errorsOccured;
147 const std::string& s)
157 XMLString::transcode(
"LS 3.0 Core 2.0", tempStr, 99);
158 DOMImplementation* implementation = DOMImplementationRegistry::getDOMImplementation(tempStr);
159 DOMLSSerializer* serializer =
static_cast<DOMImplementationLS*
>(implementation)->createLSSerializer();
163 XMLFormatTarget* target =
new LocalFileFormatTarget(s.c_str());
164 DOMLSOutput* domoutput =
static_cast<DOMImplementationLS*
>(implementation)->createLSOutput();
166 if(
m_doc->getDOMConfig()->canSetParameter(XMLUni::fgDOMComments,
true) )
m_doc->getDOMConfig()->setParameter(XMLUni::fgDOMComments,
false);
167 m_doc->normalizeDocument();
169 domoutput->setByteStream(target);
170 serializer->write(
m_doc, domoutput);
171 domoutput->release();
172 serializer->release();
182 log<<MSG::WARNING<<
"navigateTree() - something is wrong! no document set! doing nothing!"<<
endmsg;
186 node =
dynamic_cast<DOMNode*
>(
m_doc->getDocumentElement());
187 if( !
node ) std::abort();
198 log<<MSG::WARNING<<
"Calling elementLoop() with NULL pointer!!!"<<
endmsg;
201 if (!(
e->getNodeType()==DOMNode::ELEMENT_NODE))
return;
202 XMLHandler *
h =
m_xs.GetHandler(e);
207 stopLoop=
h->IsLoopToBeStopped();
213 char*
name=XMLString::transcode(
e->getNodeName());
215 XMLString::release(&name);
216 for (child=
e->getFirstChild();child!=0;child=child->getNextSibling())
218 if (child->getNodeType()==DOMNode::ELEMENT_NODE) {
228 XMLPlatformUtils::Initialize();
231 catch(
const XMLException &toCatch) {
232 XERCES_STD_QUALIFIER cerr <<
"Error during Xerces-c Initialization.\n"
233 <<
" Exception message:"
234 << XERCES_STD_QUALIFIER endl;
243 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::DOMDocument * m_doc
std::unique_ptr< xercesc::XercesDOMParser > m_parser
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)