Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:12:35

0001 // @(#)root/xml:$Id$
0002 // Author: Sergey Linev  10.05.2004
0003 
0004 /*************************************************************************
0005  * Copyright (C) 1995-2004, Rene Brun and Fons Rademakers.               *
0006  * All rights reserved.                                                  *
0007  *                                                                       *
0008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
0009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
0010  *************************************************************************/
0011 
0012 #ifndef ROOT_TXMLEngine
0013 #define ROOT_TXMLEngine
0014 
0015 #include "TObject.h"
0016 
0017 typedef void *XMLNodePointer_t;
0018 typedef void *XMLNsPointer_t;
0019 typedef void *XMLAttrPointer_t;
0020 typedef void *XMLDocPointer_t;
0021 
0022 class TXMLInputStream;
0023 class TXMLOutputStream;
0024 class TString;
0025 
0026 class TXMLEngine : public TObject {
0027 
0028 protected:
0029    char *Makestr(const char *str);
0030    char *Makenstr(const char *start, int len);
0031    XMLNodePointer_t AllocateNode(int namelen, XMLNodePointer_t parent);
0032    XMLAttrPointer_t AllocateAttr(int namelen, int valuelen, XMLNodePointer_t xmlnode);
0033    XMLNsPointer_t FindNs(XMLNodePointer_t xmlnode, const char *nsname);
0034    void TruncateNsExtension(XMLNodePointer_t xmlnode);
0035    void UnpackSpecialCharacters(char *target, const char *source, int srclen);
0036    void OutputValue(char *value, TXMLOutputStream *out);
0037    void SaveNode(XMLNodePointer_t xmlnode, TXMLOutputStream *out, Int_t layout, Int_t level);
0038    XMLNodePointer_t ReadNode(XMLNodePointer_t xmlparent, TXMLInputStream *inp, Int_t &resvalue);
0039    void DisplayError(Int_t error, Int_t linenumber);
0040    XMLDocPointer_t ParseStream(TXMLInputStream *input);
0041 
0042    Bool_t fSkipComments; //! if true, do not create comments nodes in document during parsing
0043 
0044 public:
0045    TXMLEngine();
0046    ~TXMLEngine() override;
0047 
0048    void SetSkipComments(Bool_t on = kTRUE) { fSkipComments = on; }
0049    Bool_t GetSkipComments() const { return fSkipComments; }
0050 
0051    Bool_t HasAttr(XMLNodePointer_t xmlnode, const char *name);
0052    const char *GetAttr(XMLNodePointer_t xmlnode, const char *name);
0053    Int_t GetIntAttr(XMLNodePointer_t node, const char *name);
0054    XMLAttrPointer_t NewAttr(XMLNodePointer_t xmlnode, XMLNsPointer_t, const char *name, const char *value);
0055    XMLAttrPointer_t NewIntAttr(XMLNodePointer_t xmlnode, const char *name, Int_t value);
0056    void FreeAttr(XMLNodePointer_t xmlnode, const char *name);
0057    void FreeAllAttr(XMLNodePointer_t xmlnode);
0058    XMLAttrPointer_t GetFirstAttr(XMLNodePointer_t xmlnode);
0059    XMLAttrPointer_t GetNextAttr(XMLAttrPointer_t xmlattr);
0060    const char *GetAttrName(XMLAttrPointer_t xmlattr);
0061    const char *GetAttrValue(XMLAttrPointer_t xmlattr);
0062    XMLNodePointer_t NewChild(XMLNodePointer_t parent, XMLNsPointer_t ns, const char *name, const char *content = nullptr);
0063    XMLNsPointer_t NewNS(XMLNodePointer_t xmlnode, const char *reference, const char *name = nullptr);
0064    XMLNsPointer_t GetNS(XMLNodePointer_t xmlnode);
0065    const char *GetNSName(XMLNsPointer_t ns);
0066    const char *GetNSReference(XMLNsPointer_t ns);
0067    void AddChild(XMLNodePointer_t parent, XMLNodePointer_t child);
0068    void AddChildFirst(XMLNodePointer_t parent, XMLNodePointer_t child);
0069    void AddChildAfter(XMLNodePointer_t parent, XMLNodePointer_t child, XMLNodePointer_t afternode);
0070    Bool_t AddComment(XMLNodePointer_t parent, const char *comment);
0071    Bool_t AddDocComment(XMLDocPointer_t xmldoc, const char *comment);
0072    Bool_t AddRawLine(XMLNodePointer_t parent, const char *line);
0073    Bool_t AddDocRawLine(XMLDocPointer_t xmldoc, const char *line);
0074    Bool_t AddStyleSheet(XMLNodePointer_t parent, const char *href, const char *type = "text/css", const char *title = nullptr,
0075                         int alternate = -1, const char *media = nullptr, const char *charset = nullptr);
0076    Bool_t AddDocStyleSheet(XMLDocPointer_t xmldoc, const char *href, const char *type = "text/css",
0077                            const char *title = nullptr, int alternate = -1, const char *media = nullptr, const char *charset = nullptr);
0078    void UnlinkNode(XMLNodePointer_t node);
0079    void FreeNode(XMLNodePointer_t xmlnode);
0080    void UnlinkFreeNode(XMLNodePointer_t xmlnode);
0081    const char *GetNodeName(XMLNodePointer_t xmlnode);
0082    const char *GetNodeContent(XMLNodePointer_t xmlnode);
0083    void SetNodeContent(XMLNodePointer_t xmlnode, const char *content, Int_t len = 0);
0084    void AddNodeContent(XMLNodePointer_t xmlnode, const char *content, Int_t len = 0);
0085    XMLNodePointer_t GetChild(XMLNodePointer_t xmlnode, Bool_t realnode = kTRUE);
0086    XMLNodePointer_t GetParent(XMLNodePointer_t xmlnode);
0087    XMLNodePointer_t GetNext(XMLNodePointer_t xmlnode, Bool_t realnode = kTRUE);
0088    void ShiftToNext(XMLNodePointer_t &xmlnode, Bool_t realnode = kTRUE);
0089    Bool_t IsXmlNode(XMLNodePointer_t xmlnode);
0090    Bool_t IsEmptyNode(XMLNodePointer_t xmlnode);
0091    Bool_t IsContentNode(XMLNodePointer_t xmlnode);
0092    Bool_t IsCommentNode(XMLNodePointer_t xmlnode);
0093    void SkipEmpty(XMLNodePointer_t &xmlnode);
0094    void CleanNode(XMLNodePointer_t xmlnode);
0095    XMLDocPointer_t NewDoc(const char *version = "1.0");
0096    void AssignDtd(XMLDocPointer_t xmldoc, const char *dtdname, const char *rootname);
0097    void FreeDoc(XMLDocPointer_t xmldoc);
0098    void SaveDoc(XMLDocPointer_t xmldoc, const char *filename, Int_t layout = 1);
0099    void DocSetRootElement(XMLDocPointer_t xmldoc, XMLNodePointer_t xmlnode);
0100    XMLNodePointer_t DocGetRootElement(XMLDocPointer_t xmldoc);
0101    XMLDocPointer_t ParseFile(const char *filename, Int_t maxbuf = 100000);
0102    XMLDocPointer_t ParseString(const char *xmlstring);
0103    Bool_t ValidateVersion(XMLDocPointer_t doc, const char *version = nullptr);
0104    Bool_t ValidateDocument(XMLDocPointer_t, Bool_t = kFALSE) { return kFALSE; } // obsolete
0105    void SaveSingleNode(XMLNodePointer_t xmlnode, TString *res, Int_t layout = 1);
0106    XMLNodePointer_t ReadSingleNode(const char *src);
0107 
0108    ClassDefOverride(TXMLEngine, 1); // ROOT XML I/O parser, user by TXMLFile to read/write xml files
0109 };
0110 
0111 #endif