1 /******************************************************************/ 2 /* Declaration of XML document processing using MS DOM */ 3 /* Author: Olivier Bertrand 2007 - 2012 */ 4 /******************************************************************/ 5 #include "plgxml.h" 6 7 typedef class DOMDOC *PDOMDOC; 8 typedef class DOMNODE *PDOMNODE; 9 typedef class DOMATTR *PDOMATTR; 10 typedef class DOMNODELIST *PDOMLIST; 11 12 /******************************************************************/ 13 /* XML block. Must have the same layout than FBLOCK up to Type. */ 14 /******************************************************************/ 15 typedef struct _xblock { /* Loaded XML file block */ 16 struct _xblock *Next; 17 LPCSTR Fname; /* Point on file name */ 18 size_t Length; /* Used to tell if read mode */ 19 short Count; /* Nb of times file is used */ 20 short Type; /* TYPE_FB_XML */ 21 int Retcode; /* Return code from Load */ 22 MSXML2::IXMLDOMDocumentPtr Docp;/* Document interface pointer */ 23 } XBLOCK, *PXBLOCK; 24 25 /******************************************************************/ 26 /* Declaration of DOM document. */ 27 /******************************************************************/ 28 class DOMDOC : public XMLDOCUMENT { 29 friend class DOMNODE; 30 public: 31 // Constructor 32 DOMDOC(char *nsl, char *nsdf, char *enc, PFBLOCK fp); 33 34 // Properties GetDocType(void)35 virtual short GetDocType(void) {return TYPE_FB_XML;} GetDocPtr(void)36 virtual void *GetDocPtr(void) {return Docp;} SetNofree(bool b)37 virtual void SetNofree(bool b) {} // Only libxml2 38 39 // Methods 40 virtual bool Initialize(PGLOBAL g, PCSZ entry, bool zipped); 41 virtual bool ParseFile(PGLOBAL g, char *fn); 42 virtual bool NewDoc(PGLOBAL g, PCSZ ver); 43 virtual void AddComment(PGLOBAL g, char *com); 44 virtual PXNODE GetRoot(PGLOBAL g); 45 virtual PXNODE NewRoot(PGLOBAL g, char *name); 46 virtual PXNODE NewPnode(PGLOBAL g, char *name); 47 virtual PXATTR NewPattr(PGLOBAL g); 48 virtual PXLIST NewPlist(PGLOBAL g); 49 virtual int DumpDoc(PGLOBAL g, char *ofn); 50 virtual void CloseDoc(PGLOBAL g, PFBLOCK xp); 51 virtual PFBLOCK LinkXblock(PGLOBAL g, MODE m, int rc, char *fn); 52 53 protected: 54 // Members 55 MSXML2::IXMLDOMDocumentPtr Docp; 56 MSXML2::IXMLDOMNodeListPtr Nlist; 57 HRESULT Hr; 58 }; // end of class DOMDOC 59 60 /******************************************************************/ 61 /* Declaration of DOM XML node. */ 62 /******************************************************************/ 63 class DOMNODE : public XMLNODE { 64 friend class DOMDOC; 65 friend class DOMNODELIST; 66 public: 67 // Properties 68 virtual char *GetName(PGLOBAL g); GetType(void)69 virtual int GetType(void) {return Nodep->nodeType;} 70 virtual PXNODE GetNext(PGLOBAL g); 71 virtual PXNODE GetChild(PGLOBAL g); 72 73 // Methods 74 virtual RCODE GetContent(PGLOBAL g, char *buf, int len); 75 virtual bool SetContent(PGLOBAL g, char *txtp, int len); 76 virtual PXNODE Clone(PGLOBAL g, PXNODE np); 77 virtual PXLIST GetChildElements(PGLOBAL g, char *xp, PXLIST lp); 78 virtual PXLIST SelectNodes(PGLOBAL g, char *xp, PXLIST lp); 79 virtual PXNODE SelectSingleNode(PGLOBAL g, char *xp, PXNODE np); 80 virtual PXATTR GetAttribute(PGLOBAL g, char *name, PXATTR ap); 81 virtual PXNODE AddChildNode(PGLOBAL g, PCSZ name, PXNODE np); 82 virtual PXATTR AddProperty(PGLOBAL g, char *name, PXATTR ap); 83 virtual void AddText(PGLOBAL g, PCSZ txtp); 84 virtual void DeleteChild(PGLOBAL g, PXNODE dnp); 85 86 protected: 87 // Constructor 88 DOMNODE(PXDOC dp, MSXML2::IXMLDOMNodePtr np); 89 90 // Members 91 MSXML2::IXMLDOMDocumentPtr Docp; 92 MSXML2::IXMLDOMNodePtr Nodep; 93 char Name[64]; 94 WCHAR *Ws; 95 int Len; 96 bool Zip; 97 }; // end of class DOMNODE 98 99 /******************************************************************/ 100 /* Declaration of DOM XML node list. */ 101 /******************************************************************/ 102 class DOMNODELIST : public XMLNODELIST { 103 friend class DOMDOC; 104 friend class DOMNODE; 105 public: 106 // Methods GetLength(void)107 virtual int GetLength(void) {return Listp->length;} 108 virtual PXNODE GetItem(PGLOBAL g, int n, PXNODE np); 109 virtual bool DropItem(PGLOBAL g, int n); 110 111 protected: 112 // Constructor 113 DOMNODELIST(PXDOC dp, MSXML2::IXMLDOMNodeListPtr lp); 114 115 // Members 116 MSXML2::IXMLDOMNodeListPtr Listp; 117 }; // end of class DOMNODELIST 118 119 /******************************************************************/ 120 /* Declaration of DOM XML attribute. */ 121 /******************************************************************/ 122 class DOMATTR : public XMLATTRIBUTE { 123 friend class DOMDOC; 124 friend class DOMNODE; 125 public: 126 // Properties 127 virtual char *GetName(PGLOBAL g); 128 virtual PXATTR GetNext(PGLOBAL); 129 130 // Methods 131 virtual RCODE GetText(PGLOBAL g, char *bufp, int len); 132 virtual bool SetText(PGLOBAL g, char *txtp, int len); 133 134 protected: 135 // Constructor 136 DOMATTR(PXDOC dp, MSXML2::IXMLDOMAttributePtr ap, 137 MSXML2::IXMLDOMNamedNodeMapPtr nmp = NULL); 138 139 // Members 140 MSXML2::IXMLDOMAttributePtr Atrp; 141 MSXML2::IXMLDOMNamedNodeMapPtr Nmp; 142 char Name[64]; 143 WCHAR *Ws; 144 int Len; 145 long K; 146 }; // end of class DOMATTR 147