Logo ROOT  
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 #include "TObject.h"
16 
17 typedef void *XMLNodePointer_t;
18 typedef void *XMLNsPointer_t;
19 typedef void *XMLAttrPointer_t;
20 typedef void *XMLDocPointer_t;
21 
22 class TXMLInputStream;
23 class TXMLOutputStream;
24 class TString;
25 
26 class TXMLEngine : public TObject {
27 
28 protected:
29  char *Makestr(const char *str);
30  char *Makenstr(const char *start, int len);
31  XMLNodePointer_t AllocateNode(int namelen, XMLNodePointer_t parent);
32  XMLAttrPointer_t AllocateAttr(int namelen, int valuelen, XMLNodePointer_t xmlnode);
33  XMLNsPointer_t FindNs(XMLNodePointer_t xmlnode, const char *nsname);
35  void UnpackSpecialCharacters(char *target, const char *source, int srclen);
36  void OutputValue(char *value, TXMLOutputStream *out);
37  void SaveNode(XMLNodePointer_t xmlnode, TXMLOutputStream *out, Int_t layout, Int_t level);
38  XMLNodePointer_t ReadNode(XMLNodePointer_t xmlparent, TXMLInputStream *inp, Int_t &resvalue);
39  void DisplayError(Int_t error, Int_t linenumber);
40  XMLDocPointer_t ParseStream(TXMLInputStream *input);
41 
42  Bool_t fSkipComments; //! if true, do not create comments nodes in document during parsing
43 
44 public:
45  TXMLEngine();
46  virtual ~TXMLEngine();
47 
49  Bool_t GetSkipComments() const { return fSkipComments; }
50 
51  Bool_t HasAttr(XMLNodePointer_t xmlnode, const char *name);
52  const char *GetAttr(XMLNodePointer_t xmlnode, const char *name);
53  Int_t GetIntAttr(XMLNodePointer_t node, const char *name);
54  XMLAttrPointer_t NewAttr(XMLNodePointer_t xmlnode, XMLNsPointer_t, const char *name, const char *value);
55  XMLAttrPointer_t NewIntAttr(XMLNodePointer_t xmlnode, const char *name, Int_t value);
56  void FreeAttr(XMLNodePointer_t xmlnode, const char *name);
57  void FreeAllAttr(XMLNodePointer_t xmlnode);
60  const char *GetAttrName(XMLAttrPointer_t xmlattr);
61  const char *GetAttrValue(XMLAttrPointer_t xmlattr);
62  XMLNodePointer_t NewChild(XMLNodePointer_t parent, XMLNsPointer_t ns, const char *name, const char *content = nullptr);
63  XMLNsPointer_t NewNS(XMLNodePointer_t xmlnode, const char *reference, const char *name = nullptr);
65  const char *GetNSName(XMLNsPointer_t ns);
66  const char *GetNSReference(XMLNsPointer_t ns);
67  void AddChild(XMLNodePointer_t parent, XMLNodePointer_t child);
69  void AddChildAfter(XMLNodePointer_t parent, XMLNodePointer_t child, XMLNodePointer_t afternode);
70  Bool_t AddComment(XMLNodePointer_t parent, const char *comment);
71  Bool_t AddDocComment(XMLDocPointer_t xmldoc, const char *comment);
72  Bool_t AddRawLine(XMLNodePointer_t parent, const char *line);
73  Bool_t AddDocRawLine(XMLDocPointer_t xmldoc, const char *line);
74  Bool_t AddStyleSheet(XMLNodePointer_t parent, const char *href, const char *type = "text/css", const char *title = nullptr,
75  int alternate = -1, const char *media = nullptr, const char *charset = nullptr);
76  Bool_t AddDocStyleSheet(XMLDocPointer_t xmldoc, const char *href, const char *type = "text/css",
77  const char *title = nullptr, int alternate = -1, const char *media = nullptr, const char *charset = nullptr);
78  void UnlinkNode(XMLNodePointer_t node);
79  void FreeNode(XMLNodePointer_t xmlnode);
80  void UnlinkFreeNode(XMLNodePointer_t xmlnode);
81  const char *GetNodeName(XMLNodePointer_t xmlnode);
82  const char *GetNodeContent(XMLNodePointer_t xmlnode);
83  void SetNodeContent(XMLNodePointer_t xmlnode, const char *content, Int_t len = 0);
84  void AddNodeContent(XMLNodePointer_t xmlnode, const char *content, Int_t len = 0);
88  void ShiftToNext(XMLNodePointer_t &xmlnode, Bool_t realnode = kTRUE);
93  void SkipEmpty(XMLNodePointer_t &xmlnode);
94  void CleanNode(XMLNodePointer_t xmlnode);
95  XMLDocPointer_t NewDoc(const char *version = "1.0");
96  void AssignDtd(XMLDocPointer_t xmldoc, const char *dtdname, const char *rootname);
97  void FreeDoc(XMLDocPointer_t xmldoc);
98  void SaveDoc(XMLDocPointer_t xmldoc, const char *filename, Int_t layout = 1);
101  XMLDocPointer_t ParseFile(const char *filename, Int_t maxbuf = 100000);
102  XMLDocPointer_t ParseString(const char *xmlstring);
103  Bool_t ValidateVersion(XMLDocPointer_t doc, const char *version = nullptr);
105  void SaveSingleNode(XMLNodePointer_t xmlnode, TString *res, Int_t layout = 1);
106  XMLNodePointer_t ReadSingleNode(const char *src);
107 
108  ClassDef(TXMLEngine, 1); // ROOT XML I/O parser, user by TXMLFile to read/write xml files
109 };
110 
111 #endif
TXMLEngine::IsEmptyNode
Bool_t IsEmptyNode(XMLNodePointer_t xmlnode)
return kTRUE is this is node with special data like comments to data processing instructions
Definition: TXMLEngine.cxx:1199
TXMLEngine::GetSkipComments
Bool_t GetSkipComments() const
Definition: TXMLEngine.h:49
TXMLEngine::NewAttr
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:583
TXMLEngine::ParseString
XMLDocPointer_t ParseString(const char *xmlstring)
parses content of string and tries to produce xml structures
Definition: TXMLEngine.cxx:1366
kTRUE
const Bool_t kTRUE
Definition: RtypesCore.h:91
TXMLEngine::ValidateVersion
Bool_t ValidateVersion(XMLDocPointer_t doc, const char *version=nullptr)
check that first node is xml processing instruction with correct xml version number
Definition: TXMLEngine.cxx:1417
TXMLEngine::SkipEmpty
void SkipEmpty(XMLNodePointer_t &xmlnode)
Skip all current empty nodes and locate on first "true" node.
Definition: TXMLEngine.cxx:1223
TXMLEngine::NewChild
XMLNodePointer_t NewChild(XMLNodePointer_t parent, XMLNsPointer_t ns, const char *name, const char *content=nullptr)
create new child element for parent node
Definition: TXMLEngine.cxx:712
XMLDocPointer_t
void * XMLDocPointer_t
Definition: TXMLEngine.h:20
TXMLEngine::HasAttr
Bool_t HasAttr(XMLNodePointer_t xmlnode, const char *name)
checks if node has attribute of specified name
Definition: TXMLEngine.cxx:536
TXMLEngine::CleanNode
void CleanNode(XMLNodePointer_t xmlnode)
remove all children node from xmlnode
Definition: TXMLEngine.cxx:1232
TXMLEngine::SaveDoc
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...
Definition: TXMLEngine.cxx:1303
TXMLEngine::GetAttr
const char * GetAttr(XMLNodePointer_t xmlnode, const char *name)
returns value of attribute for xmlnode
Definition: TXMLEngine.cxx:552
TXMLEngine::AddChild
void AddChild(XMLNodePointer_t parent, XMLNodePointer_t child)
add child element to xmlnode
Definition: TXMLEngine.cxx:796
TXMLEngine::ShiftToNext
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
Definition: TXMLEngine.cxx:1179
TXMLEngine::UnpackSpecialCharacters
void UnpackSpecialCharacters(char *target, const char *source, int srclen)
unpack special symbols, used in xml syntax to code characters these symbols: '<' - &lt,...
Definition: TXMLEngine.cxx:1595
TXMLEngine::DocGetRootElement
XMLNodePointer_t DocGetRootElement(XMLDocPointer_t xmldoc)
returns root node of document
Definition: TXMLEngine.cxx:1336
TXMLEngine::TruncateNsExtension
void TruncateNsExtension(XMLNodePointer_t xmlnode)
removes namespace extension of nodename
Definition: TXMLEngine.cxx:1576
TXMLEngine::GetIntAttr
Int_t GetIntAttr(XMLNodePointer_t node, const char *name)
returns value of attribute as integer
Definition: TXMLEngine.cxx:568
TXMLEngine::ParseFile
XMLDocPointer_t ParseFile(const char *filename, Int_t maxbuf=100000)
Parses content of file and tries to produce xml structures.
Definition: TXMLEngine.cxx:1353
TXMLEngine::ReadNode
XMLNodePointer_t ReadNode(XMLNodePointer_t xmlparent, TXMLInputStream *inp, Int_t &resvalue)
Tries to construct xml node from input stream.
Definition: TXMLEngine.cxx:1772
Int_t
int Int_t
Definition: RtypesCore.h:45
TXMLEngine::AddChildFirst
void AddChildFirst(XMLNodePointer_t parent, XMLNodePointer_t child)
add node as first child
Definition: TXMLEngine.cxx:821
TXMLEngine::ReadSingleNode
XMLNodePointer_t ReadSingleNode(const char *src)
read single xmlnode from provided string
Definition: TXMLEngine.cxx:1460
TXMLEngine::AddDocComment
Bool_t AddDocComment(XMLDocPointer_t xmldoc, const char *comment)
add comment line to the top of the document
Definition: TXMLEngine.cxx:892
TXMLEngine::GetChild
XMLNodePointer_t GetChild(XMLNodePointer_t xmlnode, Bool_t realnode=kTRUE)
returns first child of xmlnode
Definition: TXMLEngine.cxx:1143
TXMLEngine::IsXmlNode
Bool_t IsXmlNode(XMLNodePointer_t xmlnode)
return kTRUE is this is normal xmlnode
Definition: TXMLEngine.cxx:1191
TXMLEngine::GetAttrName
const char * GetAttrName(XMLAttrPointer_t xmlattr)
return name of the attribute
Definition: TXMLEngine.cxx:689
TXMLEngine::AllocateNode
XMLNodePointer_t AllocateNode(int namelen, XMLNodePointer_t parent)
Allocates new xml node with specified name length.
Definition: TXMLEngine.cxx:1511
TXMLEngine::AddDocRawLine
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:929
TString
Definition: TString.h:136
TXMLEngine::GetNSReference
const char * GetNSReference(XMLNsPointer_t ns)
return reference id of namespace
Definition: TXMLEngine.cxx:788
TXMLEngine::IsContentNode
Bool_t IsContentNode(XMLNodePointer_t xmlnode)
return kTRUE is this is special node with content
Definition: TXMLEngine.cxx:1207
TXMLEngine::AssignDtd
void AssignDtd(XMLDocPointer_t xmldoc, const char *dtdname, const char *rootname)
assigns dtd filename to document
Definition: TXMLEngine.cxx:1271
Bool_t
bool Bool_t
Definition: RtypesCore.h:63
TXMLEngine::SaveSingleNode
void SaveSingleNode(XMLNodePointer_t xmlnode, TString *res, Int_t layout=1)
convert single xmlnode (and its child node) to string if layout<=0, no any spaces or newlines will be...
Definition: TXMLEngine.cxx:1447
bool
TXMLEngine::OutputValue
void OutputValue(char *value, TXMLOutputStream *out)
output value to output stream if symbols '<' '&' '>' '"' ''' appears in the string,...
Definition: TXMLEngine.cxx:1639
TXMLEngine::NewNS
XMLNsPointer_t NewNS(XMLNodePointer_t xmlnode, const char *reference, const char *name=nullptr)
create namespace attribute for xmlnode.
Definition: TXMLEngine.cxx:738
TXMLEngine::ParseStream
XMLDocPointer_t ParseStream(TXMLInputStream *input)
parses content of the stream and tries to produce xml structures
Definition: TXMLEngine.cxx:1377
TXMLEngine::AddChildAfter
void AddChildAfter(XMLNodePointer_t parent, XMLNodePointer_t child, XMLNodePointer_t afternode)
Insert new child node after already existing node.
Definition: TXMLEngine.cxx:843
TXMLEngine::GetNSName
const char * GetNSName(XMLNsPointer_t ns)
return name id of namespace
Definition: TXMLEngine.cxx:775
TXMLEngine::FreeNode
void FreeNode(XMLNodePointer_t xmlnode)
release all memory, allocated from this node and destroys node itself
Definition: TXMLEngine.cxx:1034
TXMLEngine::GetParent
XMLNodePointer_t GetParent(XMLNodePointer_t xmlnode)
returns parent of xmlnode
Definition: TXMLEngine.cxx:1155
TXMLEngine::UnlinkNode
void UnlinkNode(XMLNodePointer_t node)
unlink (detach) xmlnode from parent
Definition: TXMLEngine.cxx:1002
TXMLEngine
Definition: TXMLEngine.h:26
TXMLEngine::GetNS
XMLNsPointer_t GetNS(XMLNodePointer_t xmlnode)
return namespace attribute (if exists)
Definition: TXMLEngine.cxx:763
TXMLEngine::AddNodeContent
void AddNodeContent(XMLNodePointer_t xmlnode, const char *content, Int_t len=0)
add new content of the xmlnode old content will be preserved, one could mix content with child nodes
Definition: TXMLEngine.cxx:1125
kFALSE
const Bool_t kFALSE
Definition: RtypesCore.h:92
TXMLEngine::GetNext
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
Definition: TXMLEngine.cxx:1164
TXMLEngine::~TXMLEngine
virtual ~TXMLEngine()
destructor for TXMLEngine object
Definition: TXMLEngine.cxx:529
TXMLEngine::Makestr
char * Makestr(const char *str)
creates char* variable with copy of provided string
Definition: TXMLEngine.cxx:1483
TGeant4Unit::ns
static constexpr double ns
Definition: TGeant4SystemOfUnits.h:167
XMLAttrPointer_t
void * XMLAttrPointer_t
Definition: TXMLEngine.h:19
TXMLEngine::SaveNode
void SaveNode(XMLNodePointer_t xmlnode, TXMLOutputStream *out, Int_t layout, Int_t level)
stream data of xmlnode to output
Definition: TXMLEngine.cxx:1670
XMLNodePointer_t
void * XMLNodePointer_t
Definition: TXMLEngine.h:17
line
TLine * line
Definition: entrylistblock_figure1.C:235
TXMLEngine::ValidateDocument
Bool_t ValidateDocument(XMLDocPointer_t, Bool_t=kFALSE)
Definition: TXMLEngine.h:104
TXMLEngine::FindNs
XMLNsPointer_t FindNs(XMLNodePointer_t xmlnode, const char *nsname)
define if namespace of that name exists for xmlnode
Definition: TXMLEngine.cxx:1559
TXMLEngine::NewDoc
XMLDocPointer_t NewDoc(const char *version="1.0")
creates new xml document with provided version
Definition: TXMLEngine.cxx:1252
TXMLEngine::FreeAttr
void FreeAttr(XMLNodePointer_t xmlnode, const char *name)
remove attribute from xmlnode
Definition: TXMLEngine.cxx:619
TObject.h
TXMLEngine::SetSkipComments
void SetSkipComments(Bool_t on=kTRUE)
Definition: TXMLEngine.h:48
TXMLEngine::FreeAllAttr
void FreeAllAttr(XMLNodePointer_t xmlnode)
Free all attributes of the node.
Definition: TXMLEngine.cxx:644
TXMLEngine::AddComment
Bool_t AddComment(XMLNodePointer_t parent, const char *comment)
Adds comment line to the node.
Definition: TXMLEngine.cxx:875
TObject
Definition: TObject.h:37
ClassDef
#define ClassDef(name, id)
Definition: Rtypes.h:325
TXMLEngine::DisplayError
void DisplayError(Int_t error, Int_t linenumber)
Displays xml parsing error.
Definition: TXMLEngine.cxx:2219
TXMLEngine::DocSetRootElement
void DocSetRootElement(XMLDocPointer_t xmldoc, XMLNodePointer_t xmlnode)
set main (root) node for document
Definition: TXMLEngine.cxx:1323
name
char name[80]
Definition: TGX11.cxx:110
TXMLEngine::GetNextAttr
XMLAttrPointer_t GetNextAttr(XMLAttrPointer_t xmlattr)
return next attribute in the list
Definition: TXMLEngine.cxx:678
TXMLEngine::TXMLEngine
TXMLEngine()
if true, do not create comments nodes in document during parsing
Definition: TXMLEngine.cxx:521
TXMLEngine::AddDocStyleSheet
Bool_t 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)
Add style sheet definition on the top of document.
Definition: TXMLEngine.cxx:983
TXMLEngine::UnlinkFreeNode
void UnlinkFreeNode(XMLNodePointer_t xmlnode)
combined operation. Unlink node and free used memory
Definition: TXMLEngine.cxx:1063
ROOT::TMetaUtils::propNames::comment
static const std::string comment("comment")
type
int type
Definition: TGX11.cxx:121
TXMLEngine::SetNodeContent
void SetNodeContent(XMLNodePointer_t xmlnode, const char *content, Int_t len=0)
set content of the xmlnode if old node content was exists, it will be replaced
Definition: TXMLEngine.cxx:1098
TXMLEngine::Makenstr
char * Makenstr(const char *start, int len)
creates char* variable with copy of len symbols from provided string
Definition: TXMLEngine.cxx:1498
TXMLEngine::AllocateAttr
XMLAttrPointer_t AllocateAttr(int namelen, int valuelen, XMLNodePointer_t xmlnode)
Allocate new attribute with specified name length and value length.
Definition: TXMLEngine.cxx:1534
TXMLEngine::GetNodeName
const char * GetNodeName(XMLNodePointer_t xmlnode)
returns name of xmlnode
Definition: TXMLEngine.cxx:1072
TXMLEngine::FreeDoc
void FreeDoc(XMLDocPointer_t xmldoc)
frees allocated document data and deletes document itself
Definition: TXMLEngine.cxx:1285
TXMLEngine::IsCommentNode
Bool_t IsCommentNode(XMLNodePointer_t xmlnode)
return kTRUE is this is special node with content
Definition: TXMLEngine.cxx:1215
TXMLEngine::AddStyleSheet
Bool_t 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)
Adds style sheet definition to the specified node Creates <?xml-stylesheet alternate="yes" title="com...
Definition: TXMLEngine.cxx:950
TXMLEngine::NewIntAttr
XMLAttrPointer_t NewIntAttr(XMLNodePointer_t xmlnode, const char *name, Int_t value)
create node attribute with integer value
Definition: TXMLEngine.cxx:609
TXMLEngine::GetNodeContent
const char * GetNodeContent(XMLNodePointer_t xmlnode)
get contents (if any) of xmlnode
Definition: TXMLEngine.cxx:1080
TXMLEngine::fSkipComments
Bool_t fSkipComments
Definition: TXMLEngine.h:42
TXMLEngine::GetAttrValue
const char * GetAttrValue(XMLAttrPointer_t xmlattr)
return value of attribute
Definition: TXMLEngine.cxx:700
TXMLEngine::GetFirstAttr
XMLAttrPointer_t GetFirstAttr(XMLNodePointer_t xmlnode)
return first attribute in the list, namespace (if exists) will be skipped
Definition: TXMLEngine.cxx:662
int
TXMLEngine::AddRawLine
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:912
XMLNsPointer_t
void * XMLNsPointer_t
Definition: TXMLEngine.h:18