otsdaq  v2_01_00
HttpXmlDocument.h
1 #ifndef ots_HttpXmlDocument_h
2 #define ots_HttpXmlDocument_h
3 
4 #include "otsdaq-core/XmlUtilities/XmlDocument.h"
5 
6 #include <xercesc/parsers/XercesDOMParser.hpp>
7 #include <xercesc/dom/DOMElement.hpp>
8 #include <stdexcept>
9 #include <vector>
10 
11 namespace ots
12 {
13 
15 {
16 public:
17 
18  HttpXmlDocument(std::string cookieCode="", std::string displayName="");
19  HttpXmlDocument(const HttpXmlDocument& doc);
20  HttpXmlDocument& operator=(const HttpXmlDocument& doc);
21  ~HttpXmlDocument(void);
22 
23  void setHeader (std::string cookieCode="", std::string displayName="");
24 
25  xercesc::DOMElement* getRootDataElement () { return dataElement_; }
26 
27  xercesc::DOMElement* addTextElementToData (const std::string &field, const std::string &value = "");
28  xercesc::DOMElement* addBinaryStringToData (const std::string &field, const std::string &binary);
29 
30  void copyDataChildren (HttpXmlDocument &document);
31 
32  std::string getMatchingValue (const std::string &field, const unsigned int occurance=0);
33  void getAllMatchingValues (const std::string &field, std::vector<std::string> &retVec);
34  xercesc::DOMElement* getMatchingElement (const std::string &field, const unsigned int occurance=0);
35  xercesc::DOMElement* getMatchingElementInSubtree (xercesc::DOMElement *currEl, const std::string &field, const unsigned int occurance = 0);
36  void getAllMatchingElements (const std::string &field, std::vector< xercesc::DOMElement*> &retVec);
37  void outputXmlDocument (std::ostringstream *out, bool dispStdOut=false, bool allowWhiteSpace=false);
38  bool loadXmlDocument (const std::string &filePath);
39 
40  unsigned int getChildrenCount (xercesc::DOMElement* parent = 0);
41 
42  void removeDataElement (unsigned int dataChildIndex=0); //default to first child
43 
44 private:
45 
46  void recursiveAddElementToParent (xercesc::DOMElement* child, xercesc::DOMElement* parent, bool html=false);
47  void recursiveFindAllElements (xercesc::DOMElement *currEl, const std::string &field, std::vector<std::string> *retVec);
48  void recursiveFindAllElements (xercesc::DOMElement *currEl, const std::string &field, std::vector<xercesc::DOMElement*> *retVec);
49 
50  void recursiveOutputXmlDocument (xercesc::DOMElement *currEl, std::ostringstream *out, bool dispStdOut=false, std::string tabStr="", bool allowWhiteSpace=false);
51  void recursiveFixTextFields (xercesc::DOMElement *currEl);
52  std::string recursiveFindElementValue (xercesc::DOMElement *currEl, const std::string &field, const unsigned int occurance, unsigned int &count);
53  xercesc::DOMElement* recursiveFindElement (xercesc::DOMElement *currEl, const std::string &field, const unsigned int occurance, unsigned int &count);
54 
55 
56 
57  xercesc::DOMElement* headerElement_;
58  xercesc::DOMElement* dataElement_;
59 
60  const std::string headerTagName_;
61  const std::string dataTagName_;
62  const std::string cookieCodeTagName_;
63  const std::string displayNameTagName_;
64 };
65 
66 }
67 
68 #endif //ots_HttpXmlDocument_h