Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:47:17

0001 #ifndef HCALConfigDBTools_XMLTools_XMLDOMBlock_h
0002 #define HCALConfigDBTools_XMLTools_XMLDOMBlock_h
0003 // -*- C++ -*-
0004 //
0005 // Package:     XMLTools
0006 // Class  :     XMLDOMBlock
0007 //
0008 /**\class XMLDOMBlock XMLDOMBlock.h CalibCalorimetry/HcalTPGAlgos/interface/XMLDOMBlock.h
0009 
0010  Description: <one line class summary>
0011 
0012  Usage:
0013     <usage>
0014 
0015 */
0016 //
0017 // Original Author:  Gena Kukartsev
0018 //         Created:  Thu Sep 27 01:46:46 CEST 2007
0019 //
0020 
0021 #include <string>
0022 #include <xercesc/parsers/XercesDOMParser.hpp>
0023 #include <xercesc/sax/HandlerBase.hpp>
0024 #include <xercesc/dom/DOM.hpp>
0025 
0026 //
0027 //_____ following removed as a xalan-c component_____________________
0028 //
0029 //#include <xalanc/DOMSupport/XalanDocumentPrefixResolver.hpp>
0030 ////#include <xalanc/XPath/XObject.hpp>
0031 //#include <xalanc/XalanSourceTree/XalanSourceTreeDOMSupport.hpp>
0032 //#include <xalanc/XalanSourceTree/XalanSourceTreeInit.hpp>
0033 //#include <xalanc/XalanSourceTree/XalanSourceTreeParserLiaison.hpp>
0034 //#include <xercesc/framework/LocalFileInputSource.hpp>
0035 //#include <xalanc/XPath/XPathEvaluator.hpp>
0036 
0037 class XMLProcessor;
0038 
0039 class XMLDOMBlock {
0040   friend class XMLProcessor;
0041 
0042 public:
0043   XMLDOMBlock();
0044   XMLDOMBlock(std::string xmlFileName);  // create XML from template file
0045   XMLDOMBlock(XERCES_CPP_NAMESPACE::InputSource& _source);
0046   XMLDOMBlock(std::string _root, int rootElementName);  // create XML from scratch, second parameter is a dummy
0047 
0048   XERCES_CPP_NAMESPACE::DOMDocument* getDocument(void);
0049   XERCES_CPP_NAMESPACE::DOMDocument* getDocumentConst(void) const;
0050   XERCES_CPP_NAMESPACE::DOMDocument* getNewDocument(std::string xmlFileName);
0051   std::string& getString(void);
0052   std::string& getString(XERCES_CPP_NAMESPACE::DOMNode* _node);
0053   int write(std::string target = "stdout");
0054   virtual ~XMLDOMBlock();
0055 
0056   const char* getTagValue(const std::string& tagName,
0057                           int _item = 0,
0058                           XERCES_CPP_NAMESPACE::DOMDocument* _document = nullptr);
0059   const char* getTagValue(const std::string& tagName, int _item, XERCES_CPP_NAMESPACE::DOMElement* _document);
0060   const char* getTagAttribute(const std::string& tagName, const std::string& attrName, int _item = 0);
0061 
0062   XERCES_CPP_NAMESPACE::DOMElement* add_element(XERCES_CPP_NAMESPACE::DOMElement* parent, XMLCh* tagname, XMLCh* value);
0063 
0064   XERCES_CPP_NAMESPACE::DOMNode* setTagValue(const std::string& tagName,
0065                                              const std::string& tagValue,
0066                                              int _item = 0,
0067                                              XERCES_CPP_NAMESPACE::DOMDocument* _document = nullptr);
0068   XERCES_CPP_NAMESPACE::DOMNode* setTagValue(XERCES_CPP_NAMESPACE::DOMElement* _elem,
0069                                              const std::string& tagName,
0070                                              const std::string& tagValue,
0071                                              int _item = 0);
0072   XERCES_CPP_NAMESPACE::DOMNode* setTagValue(const std::string& tagName,
0073                                              const int& tagValue,
0074                                              int _item = 0,
0075                                              XERCES_CPP_NAMESPACE::DOMDocument* _document = nullptr);
0076   XERCES_CPP_NAMESPACE::DOMNode* setTagValue(XERCES_CPP_NAMESPACE::DOMElement* _elem,
0077                                              const std::string& tagName,
0078                                              const int& tagValue,
0079                                              int _item = 0);
0080   XERCES_CPP_NAMESPACE::DOMNode* setTagAttribute(const std::string& tagName,
0081                                                  const std::string& attrName,
0082                                                  const std::string& attrValue,
0083                                                  int _item = 0);
0084   XERCES_CPP_NAMESPACE::DOMNode* setTagAttribute(XERCES_CPP_NAMESPACE::DOMElement* _elem,
0085                                                  const std::string& tagName,
0086                                                  const std::string& attrName,
0087                                                  const std::string& attrValue,
0088                                                  int _item = 0);
0089   XERCES_CPP_NAMESPACE::DOMNode* setTagAttribute(const std::string& tagName,
0090                                                  const std::string& attrName,
0091                                                  const int& attrValue,
0092                                                  int _item = 0);
0093   XERCES_CPP_NAMESPACE::DOMNode* setTagAttribute(XERCES_CPP_NAMESPACE::DOMElement* _elem,
0094                                                  const std::string& tagName,
0095                                                  const std::string& attrName,
0096                                                  const int& attrValue,
0097                                                  int _item = 0);
0098   std::string getTimestamp(time_t _time);
0099 
0100   void parse(XERCES_CPP_NAMESPACE::InputSource& _source);
0101 
0102   XMLDOMBlock& operator+=(const XMLDOMBlock& other);
0103 
0104   //
0105   //_____ following removed as a xalan-c component_____________________
0106   //
0107   //===> Xalan-c (XPath) stuff
0108   //int read_xml_file_xalan( std::string filename );
0109   //const XObjectPtr eval_xpath( std::string context, std::string expression );
0110 
0111 protected:
0112   int init(std::string _root);
0113 
0114   XMLProcessor* theProcessor;
0115   XERCES_CPP_NAMESPACE::XercesDOMParser* parser;
0116   XERCES_CPP_NAMESPACE::ErrorHandler* errHandler;
0117   XERCES_CPP_NAMESPACE::DOMDocument* document;
0118   std::string theFileName;
0119   std::string* the_string;
0120 
0121   //
0122   //_____ following removed as a xalan-c component_____________________
0123   //
0124   // xalan objects for XPath
0125   //XalanSourceTreeInit * theSourceTreeInit;
0126   //XalanSourceTreeDOMSupport * theDOMSupport;
0127   //XalanSourceTreeParserLiaison * theLiaison;
0128   //const LocalFileInputSource * theInputSource;
0129   //XalanDocument * theDocument;
0130   //XalanDocumentPrefixResolver * thePrefixResolver;
0131   //XPathEvaluator * theEvaluator;
0132 };
0133 
0134 #endif