OSDN Git Service

df157a4a0d250c9ebe23f5dbe41e5cc82f89c725
[peercast-im/PeerCastIM.git] / c: / Git / PeerCast.root / PeerCast_1 / core / common / xml.h
1 // ------------------------------------------------
2 // File : xml.h
3 // Date: 4-apr-2002
4 // Author: giles
5 // Desc: 
6 //
7 // (c) 2002 peercast.org
8 // ------------------------------------------------
9 // This program is free software; you can redistribute it and/or modify
10 // it under the terms of the GNU General Public License as published by
11 // the Free Software Foundation; either version 2 of the License, or
12 // (at your option) any later version.
13
14 // This program is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 // GNU General Public License for more details.
18 // ------------------------------------------------
19
20 #ifndef _XML_H
21 #define _XML_H
22
23 //-----------------------
24 #include "common.h"
25 #include <stdarg.h>
26
27 //-----------------------
28 class Stream;
29
30 //-----------------------
31 class XML
32 {
33 public:
34         class Node
35     {
36     public:
37         class Attribute
38         {
39                 public:
40                 int namePos,valuePos;
41         };
42
43                 Node(const char *,...);
44
45                 void    init();
46
47         ~Node();
48         
49             void        add(Node *);
50         void    write(Stream &,int);    // output, level
51         char    *getName() {return getAttrName(0);}
52
53         char    *getAttrValue(int i) {return &attrData[attr[i].valuePos];}
54         char    *getAttrName(int i) {return &attrData[attr[i].namePos];}
55         char    *getContent()  {return contData; }
56         int             getBinaryContent(void *, int);
57
58         void    setAttributes(const char *);
59         void    setContent(const char *);
60         void    setBinaryContent(void *, int);
61
62             Node        *findNode(const char *);
63         char    *findAttr(const char *);
64         int             findAttrInt(const char *);
65         int             findAttrID(const char *);
66
67         char *contData,*attrData;
68
69         Attribute       *attr;
70         int     numAttr;
71
72         Node *child,*parent,*sibling;
73         void *userPtr;
74     };
75
76     XML()
77     {
78         root = NULL;
79     }
80
81     ~XML();
82
83     void        setRoot(Node *n);
84     void        write(Stream &);
85     void        writeCompact(Stream &);
86     void        writeHTML(Stream &);
87     void        read(Stream &);
88     Node        *findNode(const char *n);
89
90     Node *root;
91 };
92 #endif