xmlParser.h

Go to the documentation of this file.
00001 
00038 #ifndef __INCLUDE_XML_NODE__
00039 #define __INCLUDE_XML_NODE__
00040 
00041 #include <stdlib.h>
00042 
00043 #ifdef _UNICODE
00044 // If you comment the next "define" line then the library will never "switch to" _UNICODE (wchar_t*) mode (16/32 bits per characters).
00045 // This is useful when you get error messages like:
00046 //    'XMLNode::openFileHelper' : cannot convert parameter 2 from 'const char [5]' to 'const wchar_t *'
00047 // The _XMLUNICODE preprocessor variable force the XMLParser library into either utf16/32-mode (the proprocessor variable
00048 // must be defined) or utf8-mode(the pre-processor variable must be undefined).
00049 #define _XMLUNICODE
00050 #endif /* _UNICODE */
00051 
00052 #if defined(WIN32) || defined(UNDER_CE)
00053 // comment the next line if you are under windows and the compiler is not Microsoft Visual Studio (6.0 or .NET)
00054 #define _XMLWINDOWS
00055 // LG 
00056 #define _USE_XMLPARSER_DLL
00057 #define _DLL_EXPORTS_
00058 #endif /* _XMLWINDOWS */
00059 
00060 #ifdef DLLENTRY
00061 #undef  DLLENTRY
00062 #endif /* DLLENTRY */
00063 
00064 //#define _USE_XMLPARSER_DLL
00065 
00066 #ifdef _USE_XMLPARSER_DLL
00067  #ifdef _DLL_EXPORTS_
00068    #define DLLENTRY __declspec(dllexport)
00069  #else
00070    #define DLLENTRY __declspec(dllimport)
00071  #endif /* _DLL_EXPORTS_ */ 
00072 #else
00073   #define DLLENTRY
00074 #endif /* _USE_XMLPARSER_DLL */
00075 
00076 // EED  ......OOJJOOO.......
00077 //#define DLLENTRY __declspec(dllexport)
00078 
00079 
00080 // uncomment the next line if you want no support for wchar_t* (no need for the <wchar.h> or <tchar.h> libraries anymore to compile)
00081 //
00082 // --> Very strange compile errors under LINUX when commented out! JPRx
00083 // --> More oddities under Windows when uncommented.
00084 // ==> I try a '#if'
00085 //
00086 #if defined(WIN32)
00087 #else
00088   #define XML_NO_WIDE_CHAR
00089 #endif /* WIN32 */
00090 
00091 #ifdef XML_NO_WIDE_CHAR
00092 #undef _XMLWINDOWS
00093 #undef _XMLUNICODE
00094 #endif /* XML_NO_WIDE_CHAR */ 
00095 
00096 #ifdef _XMLWINDOWS
00097 #include <tchar.h>
00098 #else
00099 #define DLLENTRY
00100 #ifndef XML_NO_WIDE_CHAR
00101 #include <wchar.h> // to have 'wcsrtombs' for ANSI version
00102                    // to have 'mbsrtowcs' for UNICODE version
00103 #endif /* XML_NO_WIDE_CHAR */
00104 #endif /* _XMLWINDOWS */
00105 
00106 // Some common types for char set portable code
00107 #ifdef _XMLUNICODE
00108     #ifndef _T
00109         #define _T(c) L ## c
00110     #endif
00111     #define XMLCSTR const wchar_t *
00112     #define XMLSTR  wchar_t *
00113     #define XMLCHAR wchar_t
00114 #else
00115     #ifndef _T
00116         #define _T(c) c
00117     #endif /* -T */
00118     #define XMLCSTR const char *
00119     #define XMLSTR  char *
00120     #define XMLCHAR char
00121 #endif /* _XMLUNICODE */
00122 
00123 #ifndef FALSE
00124     #define FALSE 0
00125 #endif /* FALSE */
00126 #ifndef TRUE
00127     #define TRUE 1
00128 #endif /* TRUE */
00129 
00130 
00131 // Enumeration for XML parse errors.
00132 typedef enum XMLError
00133 {
00134     eXMLErrorNone = 0,
00135     eXMLErrorMissingEndTag,
00136     eXMLErrorEmpty,
00137     eXMLErrorFirstNotStartTag,
00138     eXMLErrorMissingTagName,
00139     eXMLErrorMissingEndTagName,
00140     eXMLErrorNoMatchingQuote,
00141     eXMLErrorUnmatchedEndTag,
00142     eXMLErrorUnmatchedEndClearTag,
00143     eXMLErrorUnexpectedToken,
00144     eXMLErrorInvalidTag,
00145     eXMLErrorNoElements,
00146     eXMLErrorFileNotFound,
00147     eXMLErrorFirstTagNotFound,
00148     eXMLErrorUnknownCharacterEntity,
00149     eXMLErrorCharConversionError,
00150     eXMLErrorCannotOpenWriteFile,
00151     eXMLErrorCannotWriteFile,
00152 
00153     eXMLErrorBase64DataSizeIsNotMultipleOf4,
00154     eXMLErrorBase64DecodeIllegalCharacter,
00155     eXMLErrorBase64DecodeTruncatedData,
00156     eXMLErrorBase64DecodeBufferTooSmall
00157 } XMLError;
00158 
00159 // Enumeration used to manage type of data. Use in conjunction with structure XMLNodeContents
00160 typedef enum XMLElementType
00161 {
00162     eNodeChild=0,
00163     eNodeAttribute=1,
00164     eNodeText=2,
00165     eNodeClear=3,
00166     eNodeNULL=4
00167 } XMLElementType;
00168 
00169 // Structure used to obtain error details if the parse fails.
00170 typedef struct XMLResults
00171 {
00172     enum XMLError error;
00173     int  nLine,nColumn;
00174 } XMLResults;
00175 
00176 // Structure for XML clear (unformatted) node (usually comments)
00177 typedef struct {
00178     XMLCSTR lpszValue; XMLCSTR lpszOpenTag; XMLCSTR lpszCloseTag;
00179 } XMLClear;
00180 
00181 // Structure for XML attribute.
00182 typedef struct {
00183     XMLCSTR lpszName; XMLCSTR lpszValue;
00184 } XMLAttribute;
00185 
00186 // Structure for XML clear tags.
00187 typedef struct {
00188     XMLCSTR lpszOpen; int openTagLen; XMLCSTR lpszClose;
00189 } ALLXMLClearTag;
00190 
00191 struct XMLNodeContents;
00192 
00193 typedef struct DLLENTRY XMLNode
00194 {
00195   private:
00196 
00197     struct XMLNodeDataTag;
00198 
00199     // protected constructors: use one of these four methods to get your first instance of XMLNode:
00200     //  - parseString
00201     //  - parseFile
00202     //  - openFileHelper
00203     //  - createXMLTopNode
00204     XMLNode(struct XMLNodeDataTag *pParent, XMLCSTR lpszName, char isDeclaration);
00205     XMLNode(struct XMLNodeDataTag *p);
00206 
00207   public:
00208 
00209     // You can create your first instance of XMLNode with these 4 functions:
00210     // (see complete explanation of parameters below)
00211 
00212     static XMLNode createXMLTopNode(XMLCSTR lpszName, char isDeclaration=FALSE);
00213     static XMLNode parseString   (XMLCSTR  lpXMLString, XMLCSTR tag=NULL, XMLResults *pResults=NULL);
00214     static XMLNode parseFile     (XMLCSTR     filename, XMLCSTR tag=NULL, XMLResults *pResults=NULL);
00215     static XMLNode openFileHelper(XMLCSTR     filename, XMLCSTR tag=NULL                           );
00216 
00217     // The tag parameter should be the name of the first tag inside the XML file.
00218     // If the tag parameter is omitted, the 3 functions return a node that represents
00219     // the head of the xml document including the declaration term (<? ... ?>).
00220 
00221     // The "openFileHelper" reports to the screen all the warnings & errors that occurred during
00222     // parsing of the XML file. Since each application has its own way to report and deal with errors,
00223     // you should rather use the "parseFile" function to parse XML files and program yourself thereafter
00224     // an "error reporting" tailored for your needs (instead of using the very crude "error reporting"
00225     // mechanism included inside the "openFileHelper" function).
00226 
00227     // If the XML document is corrupted:
00228     //   * The "openFileHelper" method will:
00229     //         - display an error message on the console (or inside a messageBox for windows).
00230     //         - stop execution (exit).
00231     //     I suggest that you write your own "openFileHelper" method tailored to your needs.
00232     //   * The 2 other methods will initialize the "pResults" variable with some information that
00233     //     can be used to trace the error.
00234     //   * If you still want to parse the file, you can use the APPROXIMATE_PARSING option as
00235     //     explained inside the note at the beginning of the "xmlParser.cpp" file.
00236     // You can have a user-friendly explanation of the parsing error with this function:
00237     static XMLCSTR getError(XMLError error);
00238     static XMLCSTR getVersion();
00239     static ALLXMLClearTag* getClearTagTable();
00240 
00241     XMLCSTR getName() const;                                         // name of the node
00242     XMLCSTR getText(int i=0) const;                                  // return ith text field
00243     int nText() const;                                               // nbr of text field
00244     XMLNode getParentNode() const;                                   // return the parent node
00245     XMLNode getChildNode(int i=0) const;                             // return ith child node
00246     XMLNode getChildNode(XMLCSTR name, int i)  const;                // return ith child node with specific name
00247                                                                      //     (return an empty node if failing)
00248     XMLNode getChildNode(XMLCSTR name, int *i=NULL) const;           // return next child node with specific name
00249                                                                      //     (return an empty node if failing)
00250     XMLNode getChildNodeWithAttribute(XMLCSTR tagName,               // return child node with specific name/attribute
00251                                       XMLCSTR attributeName,         //     (return an empty node if failing)
00252                                       XMLCSTR attributeValue=NULL,   //
00253                                       int *i=NULL)  const;           //
00254     int nChildNode(XMLCSTR name) const;                              // return the number of child node with specific name
00255     int nChildNode() const;                                          // nbr of child node
00256     XMLAttribute getAttribute(int i=0) const;                        // return ith attribute
00257     XMLCSTR      getAttributeName(int i=0) const;                    // return ith attribute name
00258     XMLCSTR      getAttributeValue(int i=0) const;                   // return ith attribute value
00259     char  isAttributeSet(XMLCSTR name) const;                        // test if an attribute with a specific name is given
00260     XMLCSTR getAttribute(XMLCSTR name, int i) const;                 // return ith attribute content with specific name
00261                                                                      //     (return a NULL if failing)
00262     XMLCSTR getAttribute(XMLCSTR name, int *i=NULL) const;           // return next attribute content with specific name
00263                                                                      //     (return a NULL if failing)
00264     int nAttribute() const;                                          // nbr of attribute
00265     XMLClear getClear(int i=0) const;                                // return ith clear field (comments)
00266     int nClear() const;                                              // nbr of clear field
00267     XMLSTR createXMLString(int nFormat=1, int *pnSize=NULL) const;   // create XML string starting from current XMLNode
00268                                                                      // if nFormat==0, no formatting is required
00269                                                                      // otherwise this returns an user friendly XML string from a
00270                                                                      // given element with appropriate white spaces and carriage returns.
00271                                                                      // if pnSize is given it returns the size in character of the string.
00272     XMLError writeToFile(XMLCSTR filename, const char *encoding=NULL, char nFormat=1) const;
00273                                                                      // save the content of an xmlNode inside a file.
00274                                                                      // the nFormat parameter has the same meaning as in the
00275                                                                      // createXMLString function. If "strictUTF8Parsing=1", the
00276                                                                      // the encoding parameter is ignored and always set to
00277                                                                      // "utf-8". If "_XMLUNICODE=1", the encoding parameter is
00278                                                                      // ignored and always set to "utf-16".
00279     XMLNodeContents enumContents(int i) const;                       // enumerate all the different contents (attribute,child,text,
00280                                                                      //     clear) of the current XMLNode. The order is reflecting
00281                                                                      //     the order of the original file/string.
00282                                                                      //     NOTE: 0 <= i < nElement();
00283     int nElement() const;                                            // nbr of different contents for current node
00284     char isEmpty() const;                                            // is this node Empty?
00285     char isDeclaration() const;                                      // is this node a declaration <? .... ?>
00286 
00287 // to allow shallow/fast copy:
00288     ~XMLNode();
00289     XMLNode(const XMLNode &A);
00290     XMLNode& operator=( const XMLNode& A );
00291 
00292     XMLNode(): d(NULL){};
00293     static XMLNode emptyXMLNode;
00294     static XMLClear emptyXMLClear;
00295     static XMLAttribute emptyXMLAttribute;
00296 
00297     // The following functions allows you to create from scratch (or update) a XMLNode structure
00298     // Start by creating your top node with the "createXMLTopNode" function and then add new nodes with the "addChild" function.
00299     // The parameter 'pos' gives the position where the childNode, the text or the XMLClearTag will be inserted.
00300     // The default value (pos=-1) inserts at the end. The value (pos=0) insert at the beginning (Insertion at the beginning is slower than at the end).
00301     // REMARK: 0 <= pos < nChild()+nText()+nClear()
00302     XMLNode       addChild(XMLCSTR lpszName, char isDeclaration=FALSE, int pos=-1);
00303     XMLAttribute *addAttribute(XMLCSTR lpszName, XMLCSTR lpszValuev);
00304     XMLCSTR       addText(XMLCSTR lpszValue, int pos=-1);
00305     XMLClear     *addClear(XMLCSTR lpszValue, XMLCSTR lpszOpen=NULL, XMLCSTR lpszClose=NULL, int pos=-1);
00306                                                                     // default values: lpszOpen=XMLNode::getClearTagTable()->lpszOpen;
00307                                                                     //                 lpszClose=XMLNode::getClearTagTable()->lpszClose;
00308     XMLNode       addChild(XMLNode nodeToAdd, int pos=-1);          // If the "nodeToAdd" has some parents, it will be detached
00309                                                                     // from it's parents before being attached to the current XMLNode
00310     // Some update functions:
00311     XMLCSTR       updateName(XMLCSTR lpszName);                                                    // change node's name
00312     XMLAttribute *updateAttribute(XMLAttribute *newAttribute, XMLAttribute *oldAttribute);         // if the attribute to update is missing, a new one will be added
00313     XMLAttribute *updateAttribute(XMLCSTR lpszNewValue, XMLCSTR lpszNewName=NULL,int i=0);         // if the attribute to update is missing, a new one will be added
00314     XMLAttribute *updateAttribute(XMLCSTR lpszNewValue, XMLCSTR lpszNewName,XMLCSTR lpszOldName);  // set lpszNewName=NULL if you don't want to change the name of the attribute
00315                                                                                                    // if the attribute to update is missing, a new one will be added
00316     XMLCSTR       updateText(XMLCSTR lpszNewValue, int i=0);                                       // if the text to update is missing, a new one will be added
00317     XMLCSTR       updateText(XMLCSTR lpszNewValue, XMLCSTR lpszOldValue);                          // if the text to update is missing, a new one will be added
00318     XMLClear     *updateClear(XMLCSTR lpszNewContent, int i=0);                                    // if the clearTag to update is missing, a new one will be added
00319     XMLClear     *updateClear(XMLClear *newP,XMLClear *oldP);                                      // if the clearTag to update is missing, a new one will be added
00320     XMLClear     *updateClear(XMLCSTR lpszNewValue, XMLCSTR lpszOldValue);                         // if the clearTag to update is missing, a new one will be added
00321 
00322     // Some deletion functions:
00323     void deleteNodeContent(char force=0);  // delete the content of this XMLNode and the subtree.
00324                                            // if force=0, while (references to this node still exist), no memory free occurs
00325                                            // if force=1, always delete the content of this XMLNode and the subtree and free associated memory
00326     void deleteAttribute(XMLCSTR lpszName);
00327     void deleteAttribute(int i=0);
00328     void deleteAttribute(XMLAttribute *anAttribute);
00329     void deleteText(int i=0);
00330     void deleteText(XMLCSTR lpszValue);
00331     void deleteClear(int i=0);
00332     void deleteClear(XMLClear *p);
00333     void deleteClear(XMLCSTR lpszValue);
00334 
00335     // The strings given as parameters for the following add and update methods (all these methods have
00336     // a name with the postfix "_WOSD" that means "WithOut String Duplication" ) will be free'd by the
00337     // XMLNode class. For example, it means that this is incorrect:
00338     //    xNode.addText_WOSD("foo");
00339     //    xNode.updateAttribute_WOSD("#newcolor" ,NULL,"color");
00340     // In opposition, this is correct:
00341     //    xNode.addText("foo");
00342     //    xNode.addText_WOSD(stringDup("foo"));
00343     //    xNode.updateAttribute("#newcolor" ,NULL,"color");
00344     //    xNode.updateAttribute_WOSD(stringDup("#newcolor"),NULL,"color");
00345     // Typically, you will never do:
00346     //    char *b=(char*)malloc(...);
00347     //    xNode.addText(b);
00348     //    free(b);
00349     // ... but rather:
00350     //    char *b=(char*)malloc(...);
00351     //    xNode.addText_WOSD(b);
00352     //    ('free(b)' is performed by the XMLNode class)
00353 
00354     static XMLNode createXMLTopNode_WOSD(XMLCSTR lpszName, char isDeclaration=FALSE);
00355     XMLNode        addChild_WOSD(XMLCSTR lpszName, char isDeclaration=FALSE, int pos=-1);
00356     XMLAttribute  *addAttribute_WOSD(XMLCSTR lpszName, XMLCSTR lpszValue);
00357     XMLCSTR        addText_WOSD(XMLCSTR lpszValue, int pos=-1);
00358     XMLClear      *addClear_WOSD(XMLCSTR lpszValue, XMLCSTR lpszOpen=NULL, XMLCSTR lpszClose=NULL, int pos=-1);
00359 
00360     XMLCSTR        updateName_WOSD(XMLCSTR lpszName);
00361     XMLAttribute  *updateAttribute_WOSD(XMLAttribute *newAttribute, XMLAttribute *oldAttribute);
00362     XMLAttribute  *updateAttribute_WOSD(XMLCSTR lpszNewValue, XMLCSTR lpszNewName=NULL,int i=0);
00363     XMLAttribute  *updateAttribute_WOSD(XMLCSTR lpszNewValue, XMLCSTR lpszNewName,XMLCSTR lpszOldName);
00364     XMLCSTR        updateText_WOSD(XMLCSTR lpszNewValue, int i=0);
00365     XMLCSTR        updateText_WOSD(XMLCSTR lpszNewValue, XMLCSTR lpszOldValue);
00366     XMLClear      *updateClear_WOSD(XMLCSTR lpszNewContent, int i=0);
00367     XMLClear      *updateClear_WOSD(XMLClear *newP,XMLClear *oldP);
00368     XMLClear      *updateClear_WOSD(XMLCSTR lpszNewValue, XMLCSTR lpszOldValue);
00369 
00370     // These are some useful functions when you want to insert a childNode, a text or a XMLClearTag in the
00371     // middle (at a specified position) of a XMLNode tree already constructed. The value returned by these
00372     // methods is to be used as last parameter (parameter 'pos') of addChild, addText or addClear.
00373     int positionOfText(int i=0) const;
00374     int positionOfText(XMLCSTR lpszValue) const;
00375     int positionOfClear(int i=0) const;
00376     int positionOfClear(XMLCSTR lpszValue) const;
00377     int positionOfClear(XMLClear *a) const;
00378     int positionOfChildNode(int i=0) const;
00379     int positionOfChildNode(XMLNode x) const;
00380     int positionOfChildNode(XMLCSTR name, int i=0) const; // return the position of the ith childNode with the specified name
00381                                                           // if (name==NULL) return the position of the ith childNode
00382 
00383     // The setGlobalOptions function allows you to change two global parameters that affect string&file
00384     // parsing. First of all, you most-probably will never have to change these 2 global parameters.
00385     // About the "guessUnicodeChars" parameter:
00386     //     If "guessUnicodeChars=1" and if this library is compiled in UNICODE mode, then the
00387     //     "parseFile" and "openFileHelper" functions will test if the file contains ASCII
00388     //     characters. If this is the case, then the file will be loaded and converted in memory to
00389     //     UNICODE before being parsed. If "guessUnicodeChars=0", no conversion will
00390     //     be performed.
00391     //
00392     //     If "guessUnicodeChars=1" and if this library is compiled in ASCII/UTF8 mode, then the
00393     //     "parseFile" and "openFileHelper" functions will test if the file contains UNICODE
00394     //     characters. If this is the case, then the file will be loaded and converted in memory to
00395     //     ASCII/UTF8 before being parsed. If "guessUnicodeChars=0", no conversion will
00396     //     be performed
00397     //
00398     //     Sometime, it's useful to set "guessUnicodeChars=0" to disable any conversion
00399     //     because the test to detect the file-type (ASCII/UTF8 or UNICODE) may fail (rarely).
00400     //
00401     // About the "strictUTF8Parsing" parameter:
00402     //     If "strictUTF8Parsing=0" then we assume that all characters have the same length of 1 byte.
00403     //     If "strictUTF8Parsing=1" then the characters have different lengths (from 1 byte to 4 bytes)
00404     //     depending on the content of the first byte of the character.
00405     // About the "dropWhiteSpace" parameter:
00406     //
00407 
00408     static void setGlobalOptions(char guessUnicodeChars=1, char strictUTF8Parsing=1, char dropWhiteSpace=1);
00409 
00410     // The next function try to guess if the character encoding is UTF-8. You most-probably will never
00411     // have to use this function. It then returns the appropriate value of the global parameter
00412     // "strictUTF8Parsing" described above. The guess is based on the content of a buffer of length
00413     // "bufLen" bytes that contains the first bytes (minimum 25 bytes; 200 bytes is a good value) of the
00414     // file to be parsed. The "openFileHelper" function is using this function to automatically compute
00415     // the value of the "strictUTF8Parsing" global parameter. There are several heuristics used to do the
00416     // guess. One of the heuristic is based on the "encoding" attribute. The original XML specifications
00417     // forbids to use this attribute to do the guess but you can still use it if you set
00418     // "useXMLEncodingAttribute" to 1 (this is the default behavior and the behavior of most parsers).
00419 
00420     static char guessUTF8ParsingParameterValue(void *buffer, int bufLen, char useXMLEncodingAttribute=1);
00421 
00422   private:
00423 
00424 // these are functions and structures used internally by the XMLNode class (don't bother about them):
00425 
00426       typedef struct XMLNodeDataTag // to allow shallow copy and "intelligent/smart" pointers (automatic delete):
00427       {
00428           XMLCSTR                lpszName;        // Element name (=NULL if root)
00429           int                    nChild,          // Number of child nodes
00430                                  nText,           // Number of text fields
00431                                  nClear,          // Number of Clear fields (comments)
00432                                  nAttribute;      // Number of attributes
00433           char                   isDeclaration;   // Whether node is an XML declaration - '<?xml ?>'
00434           struct XMLNodeDataTag  *pParent;        // Pointer to parent element (=NULL if root)
00435           XMLNode                *pChild;         // Array of child nodes
00436           XMLCSTR                *pText;          // Array of text fields
00437           XMLClear               *pClear;         // Array of clear fields
00438           XMLAttribute           *pAttribute;     // Array of attributes
00439           int                    *pOrder;         // order of the child_nodes,text_fields,clear_fields
00440           int                    ref_count;       // for garbage collection (smart pointers)
00441       } XMLNodeData;
00442       XMLNodeData *d;
00443 
00444       char parseClearTag(void *px, ALLXMLClearTag *pa);
00445       char maybeAddTxT(void *pa, XMLCSTR tokenPStr);
00446       int ParseXMLElement(void *pXML);
00447       void *addToOrder(int memInc, int *_pos, int nc, void *p, int size, XMLElementType xtype);
00448       int indexText(XMLCSTR lpszValue) const;
00449       int indexClear(XMLCSTR lpszValue) const;
00450       XMLNode addChild_priv(int,XMLCSTR,char,int);
00451       XMLAttribute *addAttribute_priv(int,XMLCSTR,XMLCSTR);
00452       XMLCSTR addText_priv(int,XMLCSTR,int);
00453       XMLClear *addClear_priv(int,XMLCSTR,XMLCSTR,XMLCSTR,int);
00454       static inline int findPosition(XMLNodeData *d, int index, XMLElementType xtype);
00455       static int CreateXMLStringR(XMLNodeData *pEntry, XMLSTR lpszMarker, int nFormat);
00456       static int removeOrderElement(XMLNodeData *d, XMLElementType t, int index);
00457       static void exactMemory(XMLNodeData *d);
00458       static int detachFromParent(XMLNodeData *d);
00459 } XMLNode;
00460 
00461 // This structure is given by the function "enumContents".
00462 typedef struct XMLNodeContents
00463 {
00464     // This dictates what's the content of the XMLNodeContent
00465     enum XMLElementType type;
00466     // should be an union to access the appropriate data.
00467     // compiler does not allow union of object with constructor... too bad.
00468     XMLNode child;
00469     XMLAttribute attrib;
00470     XMLCSTR text;
00471     XMLClear clear;
00472 
00473 } XMLNodeContents;
00474 
00475 DLLENTRY void free_XMLDLL(void *t); // {free(t);}
00476 
00477 // Duplicate (copy in a new allocated buffer) the source string. This is
00478 // a very handy function when used with all the "XMLNode::*_WOSD" functions.
00479 // (If (cbData!=0) then cbData is the number of chars to duplicate)
00480 DLLENTRY XMLSTR stringDup(XMLCSTR source, int cbData=0);
00481 
00482 // The 3 following functions are processing strings so that all the characters
00483 // &,",',<,> are replaced by their XML equivalent: &amp;, &quot;, &apos;, &lt;, &gt;.
00484 // These 3 functions are useful when creating from scratch an XML file using the
00485 // "printf", "fprintf", "cout",... functions. If you are creating from scratch an
00486 // XML file using the provided XMLNode class you cannot use these functions (the
00487 // XMLNode class does the processing job for you during rendering). The second
00488 // function ("toXMLStringFast") allows you to re-use the same output buffer
00489 // for all the conversions so that only a few memory allocations are performed.
00490 // If the output buffer is too small to contain thee resulting string, it will
00491 // be enlarged.
00492 DLLENTRY XMLSTR toXMLString(XMLCSTR source);
00493 DLLENTRY XMLSTR toXMLStringFast(XMLSTR *destBuffer,int *destSz, XMLCSTR source);
00494 
00495 // you should not use this one (there is a possibility of "destination-buffer-overflow"):
00496 DLLENTRY XMLSTR toXMLString(XMLSTR dest,XMLCSTR source);
00497 
00498 // Below is a class that allows you to include any binary data (images, sounds,...)
00499 // into an XML document using "Base64 encoding". This class is completely
00500 // separated from the rest of the xmlParser library and can be removed without any problem.
00501 // To include some binary data into an XML file, you must convert the binary data into
00502 // standard text (using "encode"). To retrieve the original binary data from the
00503 // b64-encoded text included inside the XML file use "decode". Alternatively, these
00504 // functions can also be used to "encrypt/decrypt" some critical data contained inside
00505 // the XML.
00506 
00507 class DLLENTRY XMLParserBase64Tool
00508 {
00509 public:
00510     XMLParserBase64Tool(): buf(NULL),buflen(0){}
00511     ~XMLParserBase64Tool();
00512 
00513     void freeBuffer();
00514 
00515     // returns the length of the base64 string that encodes a data buffer of size inBufLen bytes.
00516     // If "formatted" parameter is true, some space will be reserved for a carriage-return every 72 chars.
00517     static int encodeLength(int inBufLen, char formatted=0);
00518 
00519     // The "base64Encode" function returns a string containing the base64 encoding of "inByteLen" bytes
00520     // from "inByteBuf". If "formatted" parameter is true, then there will be a carriage-return every 72 chars.
00521     // The string will be free'd when the XMLParserBase64Tool object is deleted.
00522     // All returned strings are sharing the same memory space.
00523     XMLSTR encode(unsigned char *inByteBuf, unsigned int inByteLen, char formatted=0);
00524 
00525     // returns the number of bytes which will be decoded from "inString".
00526     static unsigned int decodeSize(XMLCSTR inString, XMLError *xe=NULL);
00527 
00528     // returns a pointer to a buffer containing the binary data decoded from "inString"
00529     // If "inString" is malformed NULL will be returned
00530     // The output buffer will be free'd when the XMLParserBase64Tool object is deleted.
00531     // All output buffer are sharing the same memory space.
00532     unsigned char* decode(XMLCSTR inString, int *outByteLen=NULL, XMLError *xe=NULL);
00533 
00534     // The next function is deprecated.
00535     // decodes data from "inString" to "outByteBuf". You need to provide the size (in byte) of "outByteBuf"
00536     // in "inMaxByteOutBuflen". If "outByteBuf" is not large enough or if data is malformed, then "FALSE"
00537     // will be returned; otherwise "TRUE".
00538     static unsigned char decode(XMLCSTR inString, unsigned char *outByteBuf, int inMaxByteOutBuflen, XMLError *xe=NULL);
00539 
00540 private:
00541     void *buf;
00542     int buflen;
00543     void alloc(int newsize);
00544 };
00545 
00546 #undef  DLLENTRY
00547 
00548 #endif

Generated on Wed Nov 12 11:37:08 2008 for BBTK by  doxygen 1.5.6