1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
|
/******************************************************************/
/* Declaration of XML document processing using libxml2 */
/* Author: Olivier Bertrand 2007-2012 */
/******************************************************************/
#include "plgxml.h"
typedef class LIBXMLDOC *PXDOC2;
typedef class XML2NODE *PNODE2;
typedef class XML2ATTR *PATTR2;
typedef class XML2NODELIST *PLIST2;
/******************************************************************/
/* XML2 block. Must have the same layout than FBLOCK up to Type. */
/******************************************************************/
typedef struct _x2block { /* Loaded XML file block */
struct _x2block *Next;
LPCSTR Fname; /* Point on file name */
size_t Length; /* Used to tell if read mode */
short Count; /* Nb of times file is used */
short Type; /* TYPE_FB_XML */
int Retcode; /* Return code from Load */
xmlDocPtr Docp; /* Document interface pointer */
// xmlXPathContextPtr Ctxp;
// xmlXPathObjectPtr Xop;
iconv_t Cd;
iconv_t Cd2;
} X2BLOCK, *PX2BLOCK;
/******************************************************************/
/* Declaration of libxml2 document. */
/******************************************************************/
class LIBXMLDOC : public XMLDOCUMENT {
friend class XML2NODE;
friend class XML2ATTR;
public:
// Constructor
LIBXMLDOC(char *nsl, char *nsdf, char *enc, PFBLOCK fp);
// Properties
virtual short GetDocType(void) {return TYPE_FB_XML2;}
virtual void *GetDocPtr(void) {return Docp;}
// Methods
virtual bool Initialize(PGLOBAL g);
virtual bool ParseFile(char *fn);
virtual bool NewDoc(PGLOBAL g, char *ver);
virtual void AddComment(PGLOBAL g, char *com);
virtual PXNODE GetRoot(PGLOBAL g);
virtual PXNODE NewRoot(PGLOBAL g, char *name);
virtual PXNODE NewPnode(PGLOBAL g, char *name);
virtual PXATTR NewPattr(PGLOBAL g);
virtual PXLIST NewPlist(PGLOBAL g);
virtual int DumpDoc(PGLOBAL g, char *ofn);
virtual void CloseDoc(PGLOBAL g, PFBLOCK xp);
virtual PFBLOCK LinkXblock(PGLOBAL g, MODE m, int rc, char *fn);
protected:
bool CheckDocument(FILE *of, xmlNodePtr np);
xmlNodeSetPtr GetNodeList(PGLOBAL g, xmlNodePtr np, char *xp);
int Decode(xmlChar *cnt, char *buf, int n);
xmlChar *Encode(PGLOBAL g, char *txt);
// Members
xmlDocPtr Docp;
xmlNodeSetPtr Nlist;
xmlXPathContextPtr Ctxp;
xmlXPathObjectPtr Xop;
iconv_t Cd;
iconv_t Cd2; // Temporary
char *Buf; // Temporary
}; // end of class LIBXMLDOC
/******************************************************************/
/* Declaration of libxml2 node. */
/******************************************************************/
class XML2NODE : public XMLNODE {
friend class LIBXMLDOC;
friend class XML2NODELIST;
public:
// Properties
virtual char *GetName(PGLOBAL g) {return (char*)Nodep->name;}
virtual int GetType(void);
virtual PXNODE GetNext(PGLOBAL g);
virtual PXNODE GetChild(PGLOBAL g);
// Methods
virtual char *GetText(char *buf, int len);
virtual bool SetContent(PGLOBAL g, char *txtp, int len);
virtual PXNODE Clone(PGLOBAL g, PXNODE np);
virtual PXLIST GetChildElements(PGLOBAL g, char *xp, PXLIST lp);
virtual PXLIST SelectNodes(PGLOBAL g, char *xp, PXLIST lp);
virtual PXNODE SelectSingleNode(PGLOBAL g, char *xp, PXNODE np);
virtual PXATTR GetAttribute(PGLOBAL g, char *name, PXATTR ap);
virtual PXNODE AddChildNode(PGLOBAL g, char *name, PXNODE np);
virtual PXATTR AddProperty(PGLOBAL g, char *name, PXATTR ap);
virtual void AddText(PGLOBAL g, char *txtp);
virtual void DeleteChild(PGLOBAL g, PXNODE dnp);
protected:
// Constructor
XML2NODE(PXDOC dp, xmlNodePtr np);
// Members
xmlDocPtr Docp;
xmlChar *Content;
xmlNodePtr Nodep;
}; // end of class XML2NODE
/******************************************************************/
/* Declaration of libxml2 node list. */
/******************************************************************/
class XML2NODELIST : public XMLNODELIST {
friend class LIBXMLDOC;
friend class XML2NODE;
public:
// Methods
virtual int GetLength(void);
virtual PXNODE GetItem(PGLOBAL g, int n, PXNODE np);
protected:
// Constructor
XML2NODELIST(PXDOC dp, xmlNodeSetPtr lp);
// Members
xmlNodeSetPtr Listp;
}; // end of class XML2NODELIST
/******************************************************************/
/* Declaration of libxml2 attribute. */
/******************************************************************/
class XML2ATTR : public XMLATTRIBUTE {
friend class LIBXMLDOC;
friend class XML2NODE;
public:
// Properties
//virtual char *GetText(void);
// Methods
virtual bool SetText(PGLOBAL g, char *txtp, int len);
protected:
// Constructor
XML2ATTR(PXDOC dp, xmlAttrPtr ap, xmlNodePtr np);
// Members
xmlAttrPtr Atrp;
xmlNodePtr Parent;
}; // end of class XML2ATTR
|