// @(#)root/xml:$Id$
// Author: Sergey Linev  10.05.2004

/*************************************************************************
 * Copyright (C) 1995-2004, Rene Brun and Fons Rademakers.               *
 * All rights reserved.                                                  *
 *                                                                       *
 * For the licensing terms see $ROOTSYS/LICENSE.                         *
 * For the list of contributors see $ROOTSYS/README/CREDITS.             *
 *************************************************************************/

#ifndef ROOT_TXMLEngine
#define ROOT_TXMLEngine

#ifndef ROOT_TObject
#include "TObject.h"
#endif

typedef void* XMLNodePointer_t;
typedef void* XMLNsPointer_t;
typedef void* XMLAttrPointer_t;
typedef void* XMLDocPointer_t;

class TXMLInputStream;
class TXMLOutputStream;
class TString;

class TXMLEngine : public TObject {

protected:
   char*             Makestr(const char* str);
   char*             Makenstr(const char* start, int len);
   XMLNodePointer_t  AllocateNode(int namelen, XMLNodePointer_t parent);
   XMLAttrPointer_t  AllocateAttr(int namelen, int valuelen, XMLNodePointer_t xmlnode);
   XMLNsPointer_t    FindNs(XMLNodePointer_t xmlnode, const char* nsname);
   void              TruncateNsExtension(XMLNodePointer_t xmlnode);
   void              UnpackSpecialCharacters(char* target, const char* source, int srclen);
   void              OutputValue(char* value, TXMLOutputStream* out);
   void              SaveNode(XMLNodePointer_t xmlnode, TXMLOutputStream* out, Int_t layout, Int_t level);
   XMLNodePointer_t  ReadNode(XMLNodePointer_t xmlparent, TXMLInputStream* inp, Int_t& resvalue);
   void              DisplayError(Int_t error, Int_t linenumber);
   XMLDocPointer_t   ParseStream(TXMLInputStream* input);

   Bool_t            fSkipComments;    //! if true, do not create comments nodes in document during parsing

public:
   TXMLEngine();
   virtual ~TXMLEngine();

   void              SetSkipComments(Bool_t on = kTRUE) { fSkipComments = on; }
   Bool_t            GetSkipComments() const { return fSkipComments; }

   Bool_t            HasAttr(XMLNodePointer_t xmlnode, const char* name);
   const char*       GetAttr(XMLNodePointer_t xmlnode, const char* name);
   Int_t             GetIntAttr(XMLNodePointer_t node, const char* name);
   XMLAttrPointer_t  NewAttr(XMLNodePointer_t xmlnode, XMLNsPointer_t,
                             const char* name, const char* value);
   XMLAttrPointer_t  NewIntAttr(XMLNodePointer_t xmlnode, const char* name, Int_t value);
   void              FreeAttr(XMLNodePointer_t xmlnode, const char* name);
   void              FreeAllAttr(XMLNodePointer_t xmlnode);
   XMLAttrPointer_t  GetFirstAttr(XMLNodePointer_t xmlnode);
   XMLAttrPointer_t  GetNextAttr(XMLAttrPointer_t xmlattr);
   const char*       GetAttrName(XMLAttrPointer_t xmlattr);
   const char*       GetAttrValue(XMLAttrPointer_t xmlattr);
   XMLNodePointer_t  NewChild(XMLNodePointer_t parent, XMLNsPointer_t ns,
                              const char* name, const char* content = 0);
   XMLNsPointer_t    NewNS(XMLNodePointer_t xmlnode, const char* reference, const char* name = 0);
   XMLNsPointer_t    GetNS(XMLNodePointer_t xmlnode);
   const char*       GetNSName(XMLNsPointer_t ns);
   const char*       GetNSReference(XMLNsPointer_t ns);
   void              AddChild(XMLNodePointer_t parent, XMLNodePointer_t child);
   void              AddChildFirst(XMLNodePointer_t parent, XMLNodePointer_t child);
   Bool_t            AddComment(XMLNodePointer_t parent, const char* comment);
   Bool_t            AddDocComment(XMLDocPointer_t xmldoc, const char* comment);
   Bool_t            AddRawLine(XMLNodePointer_t parent, const char* line);
   Bool_t            AddDocRawLine(XMLDocPointer_t xmldoc, const char* line);
   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);
   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);
   void              UnlinkNode(XMLNodePointer_t node);
   void              FreeNode(XMLNodePointer_t xmlnode);
   void              UnlinkFreeNode(XMLNodePointer_t xmlnode);
   const char*       GetNodeName(XMLNodePointer_t xmlnode);
   const char*       GetNodeContent(XMLNodePointer_t xmlnode);
   void              SetNodeContent(XMLNodePointer_t xmlnode, const char* content, Int_t len = 0);
   void              AddNodeContent(XMLNodePointer_t xmlnode, const char* content, Int_t len = 0);
   XMLNodePointer_t  GetChild(XMLNodePointer_t xmlnode, Bool_t realnode = kTRUE);
   XMLNodePointer_t  GetParent(XMLNodePointer_t xmlnode);
   XMLNodePointer_t  GetNext(XMLNodePointer_t xmlnode, Bool_t realnode = kTRUE);
   void              ShiftToNext(XMLNodePointer_t &xmlnode, Bool_t realnode = kTRUE);
   Bool_t            IsXmlNode(XMLNodePointer_t xmlnode);
   Bool_t            IsEmptyNode(XMLNodePointer_t xmlnode);
   Bool_t            IsContentNode(XMLNodePointer_t xmlnode);
   Bool_t            IsCommentNode(XMLNodePointer_t xmlnode);
   void              SkipEmpty(XMLNodePointer_t &xmlnode);
   void              CleanNode(XMLNodePointer_t xmlnode);
   XMLDocPointer_t   NewDoc(const char* version = "1.0");
   void              AssignDtd(XMLDocPointer_t xmldoc, const char* dtdname, const char* rootname);
   void              FreeDoc(XMLDocPointer_t xmldoc);
   void              SaveDoc(XMLDocPointer_t xmldoc, const char* filename, Int_t layout = 1);
   void              DocSetRootElement(XMLDocPointer_t xmldoc, XMLNodePointer_t xmlnode);
   XMLNodePointer_t  DocGetRootElement(XMLDocPointer_t xmldoc);
   XMLDocPointer_t   ParseFile(const char* filename, Int_t maxbuf = 100000);
   XMLDocPointer_t   ParseString(const char* xmlstring);
   Bool_t            ValidateVersion(XMLDocPointer_t doc, const char* version = 0);
   Bool_t            ValidateDocument(XMLDocPointer_t, Bool_t = kFALSE) { return kFALSE; } // obsolete
   void              SaveSingleNode(XMLNodePointer_t xmlnode, TString* res, Int_t layout = 1);
   XMLNodePointer_t  ReadSingleNode(const char* src);

   ClassDef(TXMLEngine,1);   // ROOT XML I/O parser, user by TXMLFile to read/write xml files
};

#endif
 TXMLEngine.h:1
 TXMLEngine.h:2
 TXMLEngine.h:3
 TXMLEngine.h:4
 TXMLEngine.h:5
 TXMLEngine.h:6
 TXMLEngine.h:7
 TXMLEngine.h:8
 TXMLEngine.h:9
 TXMLEngine.h:10
 TXMLEngine.h:11
 TXMLEngine.h:12
 TXMLEngine.h:13
 TXMLEngine.h:14
 TXMLEngine.h:15
 TXMLEngine.h:16
 TXMLEngine.h:17
 TXMLEngine.h:18
 TXMLEngine.h:19
 TXMLEngine.h:20
 TXMLEngine.h:21
 TXMLEngine.h:22
 TXMLEngine.h:23
 TXMLEngine.h:24
 TXMLEngine.h:25
 TXMLEngine.h:26
 TXMLEngine.h:27
 TXMLEngine.h:28
 TXMLEngine.h:29
 TXMLEngine.h:30
 TXMLEngine.h:31
 TXMLEngine.h:32
 TXMLEngine.h:33
 TXMLEngine.h:34
 TXMLEngine.h:35
 TXMLEngine.h:36
 TXMLEngine.h:37
 TXMLEngine.h:38
 TXMLEngine.h:39
 TXMLEngine.h:40
 TXMLEngine.h:41
 TXMLEngine.h:42
 TXMLEngine.h:43
 TXMLEngine.h:44
 TXMLEngine.h:45
 TXMLEngine.h:46
 TXMLEngine.h:47
 TXMLEngine.h:48
 TXMLEngine.h:49
 TXMLEngine.h:50
 TXMLEngine.h:51
 TXMLEngine.h:52
 TXMLEngine.h:53
 TXMLEngine.h:54
 TXMLEngine.h:55
 TXMLEngine.h:56
 TXMLEngine.h:57
 TXMLEngine.h:58
 TXMLEngine.h:59
 TXMLEngine.h:60
 TXMLEngine.h:61
 TXMLEngine.h:62
 TXMLEngine.h:63
 TXMLEngine.h:64
 TXMLEngine.h:65
 TXMLEngine.h:66
 TXMLEngine.h:67
 TXMLEngine.h:68
 TXMLEngine.h:69
 TXMLEngine.h:70
 TXMLEngine.h:71
 TXMLEngine.h:72
 TXMLEngine.h:73
 TXMLEngine.h:74
 TXMLEngine.h:75
 TXMLEngine.h:76
 TXMLEngine.h:77
 TXMLEngine.h:78
 TXMLEngine.h:79
 TXMLEngine.h:80
 TXMLEngine.h:81
 TXMLEngine.h:82
 TXMLEngine.h:83
 TXMLEngine.h:84
 TXMLEngine.h:85
 TXMLEngine.h:86
 TXMLEngine.h:87
 TXMLEngine.h:88
 TXMLEngine.h:89
 TXMLEngine.h:90
 TXMLEngine.h:91
 TXMLEngine.h:92
 TXMLEngine.h:93
 TXMLEngine.h:94
 TXMLEngine.h:95
 TXMLEngine.h:96
 TXMLEngine.h:97
 TXMLEngine.h:98
 TXMLEngine.h:99
 TXMLEngine.h:100
 TXMLEngine.h:101
 TXMLEngine.h:102
 TXMLEngine.h:103
 TXMLEngine.h:104
 TXMLEngine.h:105
 TXMLEngine.h:106
 TXMLEngine.h:107
 TXMLEngine.h:108
 TXMLEngine.h:109
 TXMLEngine.h:110
 TXMLEngine.h:111
 TXMLEngine.h:112
 TXMLEngine.h:113
 TXMLEngine.h:114
 TXMLEngine.h:115
 TXMLEngine.h:116
 TXMLEngine.h:117
 TXMLEngine.h:118
 TXMLEngine.h:119
 TXMLEngine.h:120
 TXMLEngine.h:121
 TXMLEngine.h:122
 TXMLEngine.h:123
 TXMLEngine.h:124