otsdaq  v2_05_02_indev
XmlDocument.h
1 #ifndef ots_XmlDocument_h
2 #define ots_XmlDocument_h
3 
4 #include <dirent.h>
5 #include <stdio.h>
6 #include <string.h>
7 #include <sys/stat.h>
8 #include <sys/types.h>
9 #include <unistd.h>
10 #include <map>
11 #include <sstream>
12 #include <string>
13 #include <vector>
14 
15 #include <xercesc/dom/DOM.hpp>
16 #include <xercesc/dom/DOMElement.hpp>
17 #include <xercesc/framework/LocalFileFormatTarget.hpp>
18 #include <xercesc/framework/StdOutFormatTarget.hpp>
19 #include <xercesc/parsers/XercesDOMParser.hpp>
20 #include <xercesc/util/OutOfMemoryException.hpp>
21 #include <xercesc/util/PlatformUtils.hpp>
22 #include <xercesc/util/XMLString.hpp>
23 
24 #if defined(XERCES_NEW_IOSTREAMS)
25 #include <iostream>
26 #else
27 #include <iostream.h>
28 #endif
29 
30 //===============================================================================================================
31 namespace ots
32 {
34 {
35  //---------------------------------------------------------------------------------------------------------------
36  public:
37  XmlDocument(std::string rootName = "ROOT");
38  XmlDocument(const XmlDocument& doc);
39  XmlDocument& operator=(const XmlDocument& doc);
40  ~XmlDocument(void);
41 
42  xercesc::DOMElement* addTextElementToParent(std::string childName, std::string childText, xercesc::DOMElement* parent);
43  xercesc::DOMElement* addTextElementToParent(std::string childName, std::string childText, std::string parentName, unsigned int parentIndex = 0);
44  void saveXmlDocument(std::string filePath);
45  void recursiveRemoveChild(xercesc::DOMElement* childEl, xercesc::DOMElement* parentEl);
46  bool loadXmlDocument(std::string filePath);
47  void outputXmlDocument(std::ostringstream* out, bool dispStdOut = false);
48  void makeDirectoryBinaryTree(std::string name, std::string rootPath, int indent, xercesc::DOMElement* anchorNode);
49  xercesc::DOMElement* populateBinaryTreeNode(xercesc::DOMElement* anchorNode, std::string name, int indent, bool isLeaf);
50  void setAnchors(std::string fSystemPath, std::string fRootPath);
51  void setDocument(xercesc::DOMDocument* doc);
52  void setDarioStyle(bool darioStyle);
53  void setRootPath(std::string rootPath) { fRootPath_ = rootPath; }
54  //---------------------------------------------------------------------------------------------------------------
55  protected:
56  void copyDocument(const xercesc::DOMDocument* toCopy, xercesc::DOMDocument* copy);
57  void recursiveElementCopy(const xercesc::DOMElement* toCopy, xercesc::DOMElement* copy);
58  void initDocument(void);
59  void initPlatform(void);
60  void terminatePlatform(void);
61  void recursiveOutputXmlDocument(xercesc::DOMElement* currEl, std::ostringstream* out, bool dispStdOut = false, std::string tabStr = "");
62  std::string escapeString(std::string inString, bool allowWhiteSpace = false);
63 
64  xercesc::DOMImplementation* theImplementation_;
65  xercesc::DOMDocument* theDocument_;
66  xercesc::DOMElement* rootElement_;
67  const std::string rootTagName_;
68 
69  xercesc::DOMDocument* doc;
70  xercesc::DOMElement* rootElem;
71  DIR* dir;
72  struct dirent* entry;
73  int lastIndent;
74  int errorCode;
75  int level;
76  std::string fullPath;
77  std::string fullFPath;
78  std::stringstream ss_;
79  std::map<int, xercesc::DOMElement*> theNodes_;
80  std::map<int, std::string> theNames_;
81  std::vector<std::string> hierarchyPaths_;
82  xercesc::DOMImplementation* impl;
83  xercesc::DOMLSSerializer* pSerializer;
84  xercesc::DOMConfiguration* pDomConfiguration;
85  bool darioXMLStyle_;
86 
87  std::string fSystemPath_;
88  std::string fRootPath_;
89  std::string fFoldersPath_;
90  std::string fFileName_;
91  std::string fThisFolderPath_;
92  int indent_;
93  std::map<bool, std::string> isALeaf_;
94 };
95 } // namespace ots
96 
97 #endif // ots_XmlDocument_h