DABC (Data Acquisition Backbone Core)  2.9.9
XmlEngine.h
Go to the documentation of this file.
1 // $Id: XmlEngine.h 4421 2019-10-10 19:23:30Z linev $
2 
3 /************************************************************
4  * The Data Acquisition Backbone Core (DABC) *
5  ************************************************************
6  * Copyright (C) 2009 - *
7  * GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
8  * Planckstr. 1, 64291 Darmstadt, Germany *
9  * Contact: http://dabc.gsi.de *
10  ************************************************************
11  * This software can be used under the GPL license *
12  * agreements as stated in LICENSE.txt file *
13  * which is part of the distribution. *
14  ************************************************************/
15 
16 #ifndef DABC_XmlEngine
17 #define DABC_XmlEngine
18 
19 #ifndef DABC_string
20 #include "dabc/string.h"
21 #endif
22 
23 namespace dabc {
24 
25  typedef void* XMLNodePointer_t;
26  typedef void* XMLNsPointer_t;
27  typedef void* XMLAttrPointer_t;
28  typedef void* XMLDocPointer_t;
29 
30  class XmlInputStream;
31  class XmlOutputStream;
32 
35  namespace Xml {
36  bool HasAttr(XMLNodePointer_t xmlnode, const char* name);
37  const char* GetAttr(XMLNodePointer_t xmlnode, const char* name);
38  int GetIntAttr(XMLNodePointer_t node, const char* name);
40  const char* name, const char* value);
41  XMLAttrPointer_t NewIntAttr(XMLNodePointer_t xmlnode, const char* name, int value);
42  void FreeAttr(XMLNodePointer_t xmlnode, const char* name);
43  void FreeAllAttr(XMLNodePointer_t xmlnode);
46  const char* GetAttrName(XMLAttrPointer_t xmlattr);
47  const char* GetAttrValue(XMLAttrPointer_t xmlattr);
49  const char* name, const char* content = nullptr);
50  XMLNsPointer_t NewNS(XMLNodePointer_t xmlnode, const char* reference, const char* name = nullptr);
52  const char* GetNSName(XMLNsPointer_t ns);
53  const char* GetNSReference(XMLNsPointer_t ns);
54  void AddChild(XMLNodePointer_t parent, XMLNodePointer_t child);
56  bool AddComment(XMLNodePointer_t parent, const char* comment);
57  bool AddDocComment(XMLDocPointer_t xmldoc, const char* comment);
58  bool AddRawLine(XMLNodePointer_t parent, const char* line);
59  bool AddDocRawLine(XMLDocPointer_t xmldoc, const char* line);
60  bool AddStyleSheet(XMLNodePointer_t parent,
61  const char* href,
62  const char* type = "text/css",
63  const char* title = nullptr,
64  int alternate = -1,
65  const char* media = nullptr,
66  const char* charset = nullptr);
68  const char* href,
69  const char* type = "text/css",
70  const char* title = nullptr,
71  int alternate = -1,
72  const char* media = nullptr,
73  const char* charset = nullptr);
74  void UnlinkNode(XMLNodePointer_t node);
75  void FreeNode(XMLNodePointer_t xmlnode);
76  void UnlinkFreeNode(XMLNodePointer_t xmlnode);
77  const char* GetNodeName(XMLNodePointer_t xmlnode);
78  const char* GetNodeContent(XMLNodePointer_t xmlnode);
82  void ShiftToNext(XMLNodePointer_t &xmlnode, bool tonode = true);
83  bool IsEmptyNode(XMLNodePointer_t xmlnode);
84  void SkipEmpty(XMLNodePointer_t &xmlnode);
85  void CleanNode(XMLNodePointer_t xmlnode);
86  XMLDocPointer_t NewDoc(const char* version = "1.0");
87  void AssignDtd(XMLDocPointer_t xmldoc, const char* dtdname, const char* rootname);
88  void FreeDoc(XMLDocPointer_t xmldoc);
89  void SaveDoc(XMLDocPointer_t xmldoc, const char* filename, int layout = 1);
92  XMLDocPointer_t ParseFile(const char* filename, bool showerr = true);
93  XMLDocPointer_t ParseString(const char* xmlstring, bool showerr = true);
94  bool ValidateVersion(XMLDocPointer_t doc, const char* version = nullptr);
95  void SaveSingleNode(XMLNodePointer_t xmlnode, std::string* res, int layout = 1);
96  XMLNodePointer_t ReadSingleNode(const char* src);
97 
98  // protected:
99 
100  char* Makestr(const char* str);
101  char* Makenstr(const char* start, int len);
102  XMLNodePointer_t AllocateNode(int namelen, XMLNodePointer_t parent);
103  XMLAttrPointer_t AllocateAttr(int namelen, int valuelen, XMLNodePointer_t xmlnode);
104  XMLNsPointer_t FindNs(XMLNodePointer_t xmlnode, const char* nsname);
106  void UnpackSpecialCharacters(char* target, const char* source, int srclen);
107  void OutputValue(char* value, XmlOutputStream* out);
108  void SaveNode(XMLNodePointer_t xmlnode, XmlOutputStream* out, int layout, int level);
109  XMLNodePointer_t ReadNode(XMLNodePointer_t xmlparent, XmlInputStream* inp, int& resvalue);
110  void DisplayError(int error, int linenumber);
111  XMLDocPointer_t ParseStream(XmlInputStream* input, bool showerr);
112 
113  }
114 }
115 
116 #endif
XMLNsPointer_t FindNs(XMLNodePointer_t xmlnode, const char *nsname)
Definition: XmlEngine.cxx:1267
int GetIntAttr(XMLNodePointer_t node, const char *name)
Definition: XmlEngine.cxx:426
bool ValidateVersion(XMLDocPointer_t doc, const char *version=nullptr)
Definition: XmlEngine.cxx:1135
void AssignDtd(XMLDocPointer_t xmldoc, const char *dtdname, const char *rootname)
Definition: XmlEngine.cxx:1000
void UnpackSpecialCharacters(char *target, const char *source, int srclen)
Definition: XmlEngine.cxx:1299
XMLDocPointer_t ParseFile(const char *filename, bool showerr=true)
Definition: XmlEngine.cxx:1078
void SaveDoc(XMLDocPointer_t xmldoc, const char *filename, int layout=1)
Definition: XmlEngine.cxx:1026
void FreeAttr(XMLNodePointer_t xmlnode, const char *name)
Definition: XmlEngine.cxx:477
bool HasAttr(XMLNodePointer_t xmlnode, const char *name)
Definition: XmlEngine.cxx:397
bool AddDocRawLine(XMLDocPointer_t xmldoc, const char *line)
Definition: XmlEngine.cxx:739
void AddChildFirst(XMLNodePointer_t parent, XMLNodePointer_t child)
Definition: XmlEngine.cxx:672
XMLAttrPointer_t GetFirstAttr(XMLNodePointer_t xmlnode)
Definition: XmlEngine.cxx:518
bool AddRawLine(XMLNodePointer_t parent, const char *line)
Definition: XmlEngine.cxx:722
XMLNodePointer_t DocGetRootElement(XMLDocPointer_t xmldoc)
Definition: XmlEngine.cxx:1062
void UnlinkFreeNode(XMLNodePointer_t xmlnode)
Definition: XmlEngine.cxx:876
const char * GetAttrValue(XMLAttrPointer_t xmlattr)
Definition: XmlEngine.cxx:553
XMLNodePointer_t GetNext(XMLNodePointer_t xmlnode)
Definition: XmlEngine.cxx:925
XMLNodePointer_t GetParent(XMLNodePointer_t xmlnode)
Definition: XmlEngine.cxx:917
const char * GetAttr(XMLNodePointer_t xmlnode, const char *name)
Definition: XmlEngine.cxx:411
void SaveNode(XMLNodePointer_t xmlnode, XmlOutputStream *out, int layout, int level)
Definition: XmlEngine.cxx:1359
void UnlinkNode(XMLNodePointer_t node)
Definition: XmlEngine.cxx:822
void AddChild(XMLNodePointer_t parent, XMLNodePointer_t child)
Definition: XmlEngine.cxx:652
void FreeNode(XMLNodePointer_t xmlnode)
Definition: XmlEngine.cxx:847
XMLAttrPointer_t NewAttr(XMLNodePointer_t xmlnode, XMLNsPointer_t, const char *name, const char *value)
Definition: XmlEngine.cxx:438
XMLAttrPointer_t NewIntAttr(XMLNodePointer_t xmlnode, const char *name, int value)
Definition: XmlEngine.cxx:465
XMLDocPointer_t ParseString(const char *xmlstring, bool showerr=true)
Definition: XmlEngine.cxx:1089
bool AddDocStyleSheet(XMLDocPointer_t xmldoc, const char *href, const char *type="text/css", const char *title=nullptr, int alternate=-1, const char *media=nullptr, const char *charset=nullptr)
Definition: XmlEngine.cxx:798
void CleanNode(XMLNodePointer_t xmlnode)
Definition: XmlEngine.cxx:962
const char * GetNodeName(XMLNodePointer_t xmlnode)
Definition: XmlEngine.cxx:885
XMLNodePointer_t GetChild(XMLNodePointer_t xmlnode)
Definition: XmlEngine.cxx:906
const char * GetNodeContent(XMLNodePointer_t xmlnode)
Definition: XmlEngine.cxx:893
XMLNsPointer_t NewNS(XMLNodePointer_t xmlnode, const char *reference, const char *name=nullptr)
Definition: XmlEngine.cxx:595
XMLNodePointer_t NewChild(XMLNodePointer_t parent, XMLNsPointer_t ns, const char *name, const char *content=nullptr)
Definition: XmlEngine.cxx:564
XMLAttrPointer_t AllocateAttr(int namelen, int valuelen, XMLNodePointer_t xmlnode)
Definition: XmlEngine.cxx:1242
XMLNodePointer_t ReadSingleNode(const char *src)
Definition: XmlEngine.cxx:1171
XMLNodePointer_t ReadNode(XMLNodePointer_t xmlparent, XmlInputStream *inp, int &resvalue)
Definition: XmlEngine.cxx:1453
void FreeDoc(XMLDocPointer_t xmldoc)
Definition: XmlEngine.cxx:1013
const char * GetNSReference(XMLNsPointer_t ns)
Definition: XmlEngine.cxx:643
void FreeAllAttr(XMLNodePointer_t xmlnode)
Definition: XmlEngine.cxx:501
XMLNsPointer_t GetNS(XMLNodePointer_t xmlnode)
Definition: XmlEngine.cxx:620
const char * GetAttrName(XMLAttrPointer_t xmlattr)
Definition: XmlEngine.cxx:542
char * Makestr(const char *str)
Definition: XmlEngine.cxx:1193
void ShiftToNext(XMLNodePointer_t &xmlnode, bool tonode=true)
Definition: XmlEngine.cxx:933
bool IsEmptyNode(XMLNodePointer_t xmlnode)
Definition: XmlEngine.cxx:945
void SaveSingleNode(XMLNodePointer_t xmlnode, std::string *res, int layout=1)
Definition: XmlEngine.cxx:1155
bool AddComment(XMLNodePointer_t parent, const char *comment)
Definition: XmlEngine.cxx:689
XMLAttrPointer_t GetNextAttr(XMLAttrPointer_t xmlattr)
Definition: XmlEngine.cxx:532
void DisplayError(int error, int linenumber)
Definition: XmlEngine.cxx:1640
void SkipEmpty(XMLNodePointer_t &xmlnode)
Definition: XmlEngine.cxx:953
XMLNodePointer_t AllocateNode(int namelen, XMLNodePointer_t parent)
Definition: XmlEngine.cxx:1218
bool AddStyleSheet(XMLNodePointer_t parent, const char *href, const char *type="text/css", const char *title=nullptr, int alternate=-1, const char *media=nullptr, const char *charset=nullptr)
Definition: XmlEngine.cxx:757
void TruncateNsExtension(XMLNodePointer_t xmlnode)
Definition: XmlEngine.cxx:1283
const char * GetNSName(XMLNsPointer_t ns)
Definition: XmlEngine.cxx:631
char * Makenstr(const char *start, int len)
Definition: XmlEngine.cxx:1206
XMLDocPointer_t NewDoc(const char *version="1.0")
Definition: XmlEngine.cxx:981
void OutputValue(char *value, XmlOutputStream *out)
Definition: XmlEngine.cxx:1332
bool AddDocComment(XMLDocPointer_t xmldoc, const char *comment)
Definition: XmlEngine.cxx:705
void DocSetRootElement(XMLDocPointer_t xmldoc, XMLNodePointer_t xmlnode)
Definition: XmlEngine.cxx:1050
XMLDocPointer_t ParseStream(XmlInputStream *input, bool showerr)
Definition: XmlEngine.cxx:1099
Event manipulation API.
Definition: api.h:23
void * XMLAttrPointer_t
Definition: XmlEngine.h:27
void * XMLNodePointer_t
Definition: XmlEngine.h:25
void * XMLNsPointer_t
Definition: XmlEngine.h:26
void * XMLDocPointer_t
Definition: XmlEngine.h:28