Logo ROOT   6.08/07
Reference Guide
TXMLEngine.h
Go to the documentation of this file.
1 // @(#)root/xml:$Id$
2 // Author: Sergey Linev 10.05.2004
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2004, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 #ifndef ROOT_TXMLEngine
13 #define ROOT_TXMLEngine
14 
15 #ifndef ROOT_TObject
16 #include "TObject.h"
17 #endif
18 
19 typedef void* XMLNodePointer_t;
20 typedef void* XMLNsPointer_t;
21 typedef void* XMLAttrPointer_t;
22 typedef void* XMLDocPointer_t;
23 
24 class TXMLInputStream;
25 class TXMLOutputStream;
26 class TString;
27 
28 class TXMLEngine : public TObject {
29 
30 protected:
31  char* Makestr(const char* str);
32  char* Makenstr(const char* start, int len);
33  XMLNodePointer_t AllocateNode(int namelen, XMLNodePointer_t parent);
34  XMLAttrPointer_t AllocateAttr(int namelen, int valuelen, XMLNodePointer_t xmlnode);
35  XMLNsPointer_t FindNs(XMLNodePointer_t xmlnode, const char* nsname);
37  void UnpackSpecialCharacters(char* target, const char* source, int srclen);
38  void OutputValue(char* value, TXMLOutputStream* out);
39  void SaveNode(XMLNodePointer_t xmlnode, TXMLOutputStream* out, Int_t layout, Int_t level);
40  XMLNodePointer_t ReadNode(XMLNodePointer_t xmlparent, TXMLInputStream* inp, Int_t& resvalue);
41  void DisplayError(Int_t error, Int_t linenumber);
42  XMLDocPointer_t ParseStream(TXMLInputStream* input);
43 
44  Bool_t fSkipComments; //! if true, do not create comments nodes in document during parsing
45 
46 public:
47  TXMLEngine();
48  virtual ~TXMLEngine();
49 
50  void SetSkipComments(Bool_t on = kTRUE) { fSkipComments = on; }
51  Bool_t GetSkipComments() const { return fSkipComments; }
52 
53  Bool_t HasAttr(XMLNodePointer_t xmlnode, const char* name);
54  const char* GetAttr(XMLNodePointer_t xmlnode, const char* name);
55  Int_t GetIntAttr(XMLNodePointer_t node, const char* name);
57  const char* name, const char* value);
58  XMLAttrPointer_t NewIntAttr(XMLNodePointer_t xmlnode, const char* name, Int_t value);
59  void FreeAttr(XMLNodePointer_t xmlnode, const char* name);
60  void FreeAllAttr(XMLNodePointer_t xmlnode);
63  const char* GetAttrName(XMLAttrPointer_t xmlattr);
64  const char* GetAttrValue(XMLAttrPointer_t xmlattr);
66  const char* name, const char* content = 0);
67  XMLNsPointer_t NewNS(XMLNodePointer_t xmlnode, const char* reference, const char* name = 0);
69  const char* GetNSName(XMLNsPointer_t ns);
70  const char* GetNSReference(XMLNsPointer_t ns);
71  void AddChild(XMLNodePointer_t parent, XMLNodePointer_t child);
73  Bool_t AddComment(XMLNodePointer_t parent, const char* comment);
74  Bool_t AddDocComment(XMLDocPointer_t xmldoc, const char* comment);
75  Bool_t AddRawLine(XMLNodePointer_t parent, const char* line);
76  Bool_t AddDocRawLine(XMLDocPointer_t xmldoc, const char* line);
78  const char* href,
79  const char* type = "text/css",
80  const char* title = 0,
81  int alternate = -1,
82  const char* media = 0,
83  const char* charset = 0);
85  const char* href,
86  const char* type = "text/css",
87  const char* title = 0,
88  int alternate = -1,
89  const char* media = 0,
90  const char* charset = 0);
91  void UnlinkNode(XMLNodePointer_t node);
92  void FreeNode(XMLNodePointer_t xmlnode);
93  void UnlinkFreeNode(XMLNodePointer_t xmlnode);
94  const char* GetNodeName(XMLNodePointer_t xmlnode);
95  const char* GetNodeContent(XMLNodePointer_t xmlnode);
96  void SetNodeContent(XMLNodePointer_t xmlnode, const char* content, Int_t len = 0);
97  void AddNodeContent(XMLNodePointer_t xmlnode, const char* content, Int_t len = 0);
101  void ShiftToNext(XMLNodePointer_t &xmlnode, Bool_t realnode = kTRUE);
106  void SkipEmpty(XMLNodePointer_t &xmlnode);
107  void CleanNode(XMLNodePointer_t xmlnode);
108  XMLDocPointer_t NewDoc(const char* version = "1.0");
109  void AssignDtd(XMLDocPointer_t xmldoc, const char* dtdname, const char* rootname);
110  void FreeDoc(XMLDocPointer_t xmldoc);
111  void SaveDoc(XMLDocPointer_t xmldoc, const char* filename, Int_t layout = 1);
112  void DocSetRootElement(XMLDocPointer_t xmldoc, XMLNodePointer_t xmlnode);
114  XMLDocPointer_t ParseFile(const char* filename, Int_t maxbuf = 100000);
115  XMLDocPointer_t ParseString(const char* xmlstring);
116  Bool_t ValidateVersion(XMLDocPointer_t doc, const char* version = 0);
118  void SaveSingleNode(XMLNodePointer_t xmlnode, TString* res, Int_t layout = 1);
119  XMLNodePointer_t ReadSingleNode(const char* src);
120 
121  ClassDef(TXMLEngine,1); // ROOT XML I/O parser, user by TXMLFile to read/write xml files
122 };
123 
124 #endif
char * Makestr(const char *str)
creates char* variable with copy of provided string
Bool_t ValidateDocument(XMLDocPointer_t, Bool_t=kFALSE)
Definition: TXMLEngine.h:117
XMLDocPointer_t ParseStream(TXMLInputStream *input)
parses content of the stream and tries to produce xml structures
void FreeAttr(XMLNodePointer_t xmlnode, const char *name)
remove attribute from xmlnode
Definition: TXMLEngine.cxx:526
XMLNsPointer_t GetNS(XMLNodePointer_t xmlnode)
return namespace attribute (if exists)
Definition: TXMLEngine.cxx:665
TLine * line
static const std::string comment("comment")
void SaveNode(XMLNodePointer_t xmlnode, TXMLOutputStream *out, Int_t layout, Int_t level)
stream data of xmlnode to output
Bool_t AddStyleSheet(XMLNodePointer_t parent, const char *href, const char *type="text/css", const char *title=0, int alternate=-1, const char *media=0, const char *charset=0)
Adds style sheet definition to the specified node Creates <?xml-stylesheet alternate="yes" title="com...
Definition: TXMLEngine.cxx:808
XMLDocPointer_t NewDoc(const char *version="1.0")
creates new xml document with provided version
TXMLEngine()
if true, do not create comments nodes in document during parsing
Definition: TXMLEngine.cxx:430
XMLNodePointer_t GetNext(XMLNodePointer_t xmlnode, Bool_t realnode=kTRUE)
return next to xmlnode node if realnode==kTRUE, any special nodes in between will be skipped ...
Basic string class.
Definition: TString.h:137
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
const Bool_t kFALSE
Definition: Rtypes.h:92
void SetSkipComments(Bool_t on=kTRUE)
Definition: TXMLEngine.h:50
Bool_t AddComment(XMLNodePointer_t parent, const char *comment)
Adds comment line to the node.
Definition: TXMLEngine.cxx:734
XMLNsPointer_t FindNs(XMLNodePointer_t xmlnode, const char *nsname)
define if namespace of that name exists for xmlnode
XMLAttrPointer_t GetNextAttr(XMLAttrPointer_t xmlattr)
return next attribute in the list
Definition: TXMLEngine.cxx:582
void FreeDoc(XMLDocPointer_t xmldoc)
frees allocated document data and deletes document itself
void UnlinkFreeNode(XMLNodePointer_t xmlnode)
combined operation. Unlink node and free used memory
Definition: TXMLEngine.cxx:921
XMLAttrPointer_t NewIntAttr(XMLNodePointer_t xmlnode, const char *name, Int_t value)
create node attribute with integer value
Definition: TXMLEngine.cxx:514
const char * GetNodeContent(XMLNodePointer_t xmlnode)
get contents (if any) of xml node
Definition: TXMLEngine.cxx:938
void DisplayError(Int_t error, Int_t linenumber)
Displays xml parsing error.
void FreeAllAttr(XMLNodePointer_t xmlnode)
Free all attributes of the node.
Definition: TXMLEngine.cxx:550
#define ClassDef(name, id)
Definition: Rtypes.h:254
void * XMLDocPointer_t
Definition: TXMLEngine.h:22
void DocSetRootElement(XMLDocPointer_t xmldoc, XMLNodePointer_t xmlnode)
set main (root) node for document
Bool_t GetSkipComments() const
Definition: TXMLEngine.h:51
XMLNsPointer_t NewNS(XMLNodePointer_t xmlnode, const char *reference, const char *name=0)
create namespace attribute for xmlnode.
Definition: TXMLEngine.cxx:641
XMLDocPointer_t ParseString(const char *xmlstring)
parses content of string and tries to produce xml structures
Bool_t IsEmptyNode(XMLNodePointer_t xmlnode)
return kTRUE is this is node with special data like comments to data processing instructions ...
const char * GetNodeName(XMLNodePointer_t xmlnode)
returns name of xmlnode
Definition: TXMLEngine.cxx:930
XMLAttrPointer_t AllocateAttr(int namelen, int valuelen, XMLNodePointer_t xmlnode)
Allocate new attribute with specified name length and value length.
void SaveDoc(XMLDocPointer_t xmldoc, const char *filename, Int_t layout=1)
store document content to file if layout<=0, no any spaces or newlines will be placed between xmlnode...
Bool_t fSkipComments
Definition: TXMLEngine.h:44
void AddChild(XMLNodePointer_t parent, XMLNodePointer_t child)
add child element to xmlnode
Definition: TXMLEngine.cxx:697
void ShiftToNext(XMLNodePointer_t &xmlnode, Bool_t realnode=kTRUE)
shifts specified node to next if realnode==kTRUE, any special nodes in between will be skipped ...
Bool_t AddRawLine(XMLNodePointer_t parent, const char *line)
Add just line into xml file Line should has correct xml syntax that later it can be decoded by xml pa...
Definition: TXMLEngine.cxx:769
void SetNodeContent(XMLNodePointer_t xmlnode, const char *content, Int_t len=0)
set content of the xml node if old node content was exists, it will be replaced
Definition: TXMLEngine.cxx:953
char * Makenstr(const char *start, int len)
creates char* variable with copy of len symbols from provided string
Bool_t IsCommentNode(XMLNodePointer_t xmlnode)
return kTRUE is this is special node with content
const char * GetAttrValue(XMLAttrPointer_t xmlattr)
return value of attribute
Definition: TXMLEngine.cxx:603
XMLAttrPointer_t GetFirstAttr(XMLNodePointer_t xmlnode)
return first attribute in the list, namespace (if exists) will be skiped
Definition: TXMLEngine.cxx:568
void * XMLNodePointer_t
Definition: TXMLEngine.h:19
Bool_t AddDocStyleSheet(XMLDocPointer_t xmldoc, const char *href, const char *type="text/css", const char *title=0, int alternate=-1, const char *media=0, const char *charset=0)
Add style sheet definition on the top of document.
Definition: TXMLEngine.cxx:843
void SkipEmpty(XMLNodePointer_t &xmlnode)
Skip all current empty nodes and locate on first "true" node.
Bool_t IsXmlNode(XMLNodePointer_t xmlnode)
return kTRUE is this is normal xml node
Bool_t HasAttr(XMLNodePointer_t xmlnode, const char *name)
checks if node has attribute of specified name
Definition: TXMLEngine.cxx:446
Bool_t AddDocRawLine(XMLDocPointer_t xmldoc, const char *line)
Add just line on the top of xml document Line should has correct xml syntax that later it can be deco...
Definition: TXMLEngine.cxx:785
XMLDocPointer_t ParseFile(const char *filename, Int_t maxbuf=100000)
Parses content of file and tries to produce xml structures.
void AddChildFirst(XMLNodePointer_t parent, XMLNodePointer_t child)
add node as first child
Definition: TXMLEngine.cxx:717
XMLAttrPointer_t NewAttr(XMLNodePointer_t xmlnode, XMLNsPointer_t, const char *name, const char *value)
creates new attribute for xmlnode, namespaces are not supported for attributes
Definition: TXMLEngine.cxx:488
void * XMLAttrPointer_t
Definition: TXMLEngine.h:21
void CleanNode(XMLNodePointer_t xmlnode)
remove all children node from xmlnode
const char * GetAttr(XMLNodePointer_t xmlnode, const char *name)
returns value of attribute for xmlnode
Definition: TXMLEngine.cxx:460
void SaveSingleNode(XMLNodePointer_t xmlnode, TString *res, Int_t layout=1)
convert single xml node (and its child node) to string if layout<=0, no any spaces or newlines will b...
Bool_t AddDocComment(XMLDocPointer_t xmldoc, const char *comment)
add comment line to the top of the document
Definition: TXMLEngine.cxx:750
int type
Definition: TGX11.cxx:120
void TruncateNsExtension(XMLNodePointer_t xmlnode)
removes namespace extension of nodename
void FreeNode(XMLNodePointer_t xmlnode)
release all memory, allocated fro this node and destroyes node itself
Definition: TXMLEngine.cxx:893
XMLNodePointer_t ReadNode(XMLNodePointer_t xmlparent, TXMLInputStream *inp, Int_t &resvalue)
Tries to construct xml node from input stream.
Mother of all ROOT objects.
Definition: TObject.h:37
Bool_t ValidateVersion(XMLDocPointer_t doc, const char *version=0)
check that first node is xml processing instruction with correct xml version number ...
void * XMLNsPointer_t
Definition: TXMLEngine.h:20
XMLNodePointer_t GetChild(XMLNodePointer_t xmlnode, Bool_t realnode=kTRUE)
returns first child of xml node
Definition: TXMLEngine.cxx:993
XMLNodePointer_t GetParent(XMLNodePointer_t xmlnode)
returns parent of xmlnode
void UnpackSpecialCharacters(char *target, const char *source, int srclen)
unpack special symbols, used in xml syntax to code characters these symbols: &#39;<&#39; - &lt, &#39;>&#39; - &gt, &#39;&&#39; - &amp, &#39;"...
const char * GetNSName(XMLNsPointer_t ns)
return name id of namespace
Definition: TXMLEngine.cxx:676
XMLNodePointer_t NewChild(XMLNodePointer_t parent, XMLNsPointer_t ns, const char *name, const char *content=0)
create new child element for parent node
Definition: TXMLEngine.cxx:614
XMLNodePointer_t DocGetRootElement(XMLDocPointer_t xmldoc)
returns root node of document
void UnlinkNode(XMLNodePointer_t node)
unlink (dettach) xml node from parent
Definition: TXMLEngine.cxx:867
Int_t GetIntAttr(XMLNodePointer_t node, const char *name)
returns value of attribute as integer
Definition: TXMLEngine.cxx:475
Bool_t IsContentNode(XMLNodePointer_t xmlnode)
return kTRUE is this is special node with content
void AddNodeContent(XMLNodePointer_t xmlnode, const char *content, Int_t len=0)
add new content of the xml node old content will be preserved, one could mix content with child nodes...
Definition: TXMLEngine.cxx:977
XMLNodePointer_t ReadSingleNode(const char *src)
read single xml node from provided string
virtual ~TXMLEngine()
destructor for TXMLEngine object
Definition: TXMLEngine.cxx:439
const Bool_t kTRUE
Definition: Rtypes.h:91
void OutputValue(char *value, TXMLOutputStream *out)
output value to output stream if symbols &#39;<&#39; &#39;&&#39; &#39;>&#39; &#39;"&#39; &#39;&#39;&#39; appears in the string, they will be encoded to appropriate xml symbols: &lt, &amp, &gt, &quot, &apos
const char * GetAttrName(XMLAttrPointer_t xmlattr)
return name of the attribute
Definition: TXMLEngine.cxx:592
XMLNodePointer_t AllocateNode(int namelen, XMLNodePointer_t parent)
Allocates new xml node with specified namelength.
char name[80]
Definition: TGX11.cxx:109
const char * GetNSReference(XMLNsPointer_t ns)
return reference id of namespace
Definition: TXMLEngine.cxx:688
void AssignDtd(XMLDocPointer_t xmldoc, const char *dtdname, const char *rootname)
assignes dtd filename to document