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
|
/******************************************************************/
/* Declaration of XML document processing using MS DOM */
/* Author: Olivier Bertrand 2007 - 2012 */
/******************************************************************/
#include "plgxml.h"
typedef class DOMDOC *PDOMDOC;
typedef class DOMNODE *PDOMNODE;
typedef class DOMATTR *PDOMATTR;
typedef class DOMNODELIST *PDOMLIST;
/******************************************************************/
/* XML block. Must have the same layout than FBLOCK up to Type. */
/******************************************************************/
typedef struct _xblock { /* Loaded XML file block */
struct _xblock *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 */
MSXML2::IXMLDOMDocumentPtr Docp;/* Document interface pointer */
} XBLOCK, *PXBLOCK;
/******************************************************************/
/* Declaration of DOM document. */
/******************************************************************/
class DOMDOC : public XMLDOCUMENT {
friend class DOMNODE;
public:
// Constructor
DOMDOC(char *nsl, char *nsdf, char *enc, PFBLOCK fp);
// Properties
virtual short GetDocType(void) {return TYPE_FB_XML;}
virtual void *GetDocPtr(void) {return Docp;}
virtual void SetNofree(bool b) {} // Only libxml2
// Methods
virtual bool Initialize(PGLOBAL g, PCSZ entry, bool zipped);
virtual bool ParseFile(PGLOBAL g, char *fn);
virtual bool NewDoc(PGLOBAL g, PCSZ 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:
// Members
MSXML2::IXMLDOMDocumentPtr Docp;
MSXML2::IXMLDOMNodeListPtr Nlist;
HRESULT Hr;
}; // end of class DOMDOC
/******************************************************************/
/* Declaration of DOM XML node. */
/******************************************************************/
class DOMNODE : public XMLNODE {
friend class DOMDOC;
friend class DOMNODELIST;
public:
// Properties
virtual char *GetName(PGLOBAL g);
virtual int GetType(void) {return Nodep->nodeType;}
virtual PXNODE GetNext(PGLOBAL g);
virtual PXNODE GetChild(PGLOBAL g);
// Methods
virtual RCODE GetContent(PGLOBAL g, 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, PCSZ name, PXNODE np);
virtual PXATTR AddProperty(PGLOBAL g, char *name, PXATTR ap);
virtual void AddText(PGLOBAL g, PCSZ txtp);
virtual void DeleteChild(PGLOBAL g, PXNODE dnp);
protected:
// Constructor
DOMNODE(PXDOC dp, MSXML2::IXMLDOMNodePtr np);
// Members
MSXML2::IXMLDOMDocumentPtr Docp;
MSXML2::IXMLDOMNodePtr Nodep;
char Name[64];
WCHAR *Ws;
int Len;
bool Zip;
}; // end of class DOMNODE
/******************************************************************/
/* Declaration of DOM XML node list. */
/******************************************************************/
class DOMNODELIST : public XMLNODELIST {
friend class DOMDOC;
friend class DOMNODE;
public:
// Methods
virtual int GetLength(void) {return Listp->length;}
virtual PXNODE GetItem(PGLOBAL g, int n, PXNODE np);
virtual bool DropItem(PGLOBAL g, int n);
protected:
// Constructor
DOMNODELIST(PXDOC dp, MSXML2::IXMLDOMNodeListPtr lp);
// Members
MSXML2::IXMLDOMNodeListPtr Listp;
}; // end of class DOMNODELIST
/******************************************************************/
/* Declaration of DOM XML attribute. */
/******************************************************************/
class DOMATTR : public XMLATTRIBUTE {
friend class DOMDOC;
friend class DOMNODE;
public:
// Properties
virtual char *GetName(PGLOBAL g);
virtual PXATTR GetNext(PGLOBAL);
// Methods
virtual RCODE GetText(PGLOBAL g, char *bufp, int len);
virtual bool SetText(PGLOBAL g, char *txtp, int len);
protected:
// Constructor
DOMATTR(PXDOC dp, MSXML2::IXMLDOMAttributePtr ap,
MSXML2::IXMLDOMNamedNodeMapPtr nmp = NULL);
// Members
MSXML2::IXMLDOMAttributePtr Atrp;
MSXML2::IXMLDOMNamedNodeMapPtr Nmp;
char Name[64];
WCHAR *Ws;
int Len;
long K;
}; // end of class DOMATTR
|