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