00001 #ifndef ots_HttpXmlDocument_h
00002 #define ots_HttpXmlDocument_h
00003
00004 #include "otsdaq-core/XmlUtilities/XmlDocument.h"
00005
00006 #include <xercesc/parsers/XercesDOMParser.hpp>
00007 #include <xercesc/dom/DOMElement.hpp>
00008 #include <stdexcept>
00009 #include <vector>
00010
00011 namespace ots
00012 {
00013
00014 class HttpXmlDocument : public XmlDocument
00015 {
00016 public:
00017
00018 HttpXmlDocument(std::string cookieCode="", std::string displayName="");
00019 HttpXmlDocument(const HttpXmlDocument& doc);
00020 HttpXmlDocument& operator=(const HttpXmlDocument& doc);
00021 ~HttpXmlDocument(void);
00022
00023 void setHeader (std::string cookieCode="", std::string displayName="");
00024
00025 xercesc::DOMElement* getRootDataElement () { return dataElement_; }
00026
00027 xercesc::DOMElement* addTextElementToData (const std::string &field, const std::string &value = "");
00028
00029 void copyDataChildren (HttpXmlDocument &document);
00030
00031 std::string getMatchingValue (const std::string &field, const unsigned int occurance=0);
00032 void getAllMatchingValues (const std::string &field, std::vector<std::string> &retVec);
00033 xercesc::DOMElement* getMatchingElement (const std::string &field, const unsigned int occurance=0);
00034 xercesc::DOMElement* getMatchingElementInSubtree (xercesc::DOMElement *currEl, const std::string &field, const unsigned int occurance = 0);
00035 void getAllMatchingElements (const std::string &field, std::vector< xercesc::DOMElement*> &retVec);
00036 void outputXmlDocument (std::ostringstream *out, bool dispStdOut=false, bool allowWhiteSpace=false);
00037 bool loadXmlDocument (const std::string &filePath);
00038
00039 unsigned int getChildrenCount (xercesc::DOMElement* parent = 0);
00040
00041 void removeDataElement (unsigned int dataChildIndex=0);
00042
00043 private:
00044
00045 void recursiveAddElementToParent (xercesc::DOMElement* child, xercesc::DOMElement* parent, bool html=false);
00046 void recursiveFindAllElements (xercesc::DOMElement *currEl, const std::string &field, std::vector<std::string> *retVec);
00047 void recursiveFindAllElements (xercesc::DOMElement *currEl, const std::string &field, std::vector<xercesc::DOMElement*> *retVec);
00048
00049 void recursiveOutputXmlDocument (xercesc::DOMElement *currEl, std::ostringstream *out, bool dispStdOut=false, std::string tabStr="", bool allowWhiteSpace=false);
00050 void recursiveFixTextFields (xercesc::DOMElement *currEl);
00051 std::string recursiveFindElementValue (xercesc::DOMElement *currEl, const std::string &field, const unsigned int occurance, unsigned int &count);
00052 xercesc::DOMElement* recursiveFindElement (xercesc::DOMElement *currEl, const std::string &field, const unsigned int occurance, unsigned int &count);
00053
00054
00055
00056 xercesc::DOMElement* headerElement_;
00057 xercesc::DOMElement* dataElement_;
00058
00059 const std::string headerTagName_;
00060 const std::string dataTagName_;
00061 const std::string cookieCodeTagName_;
00062 const std::string displayNameTagName_;
00063 };
00064
00065 }
00066
00067 #endif //ots_HttpXmlDocument_h