LLC2_API
Classes | Defines | Typedefs | Enumerations | Functions | Variables
xmlParser.cpp File Reference
#include "xmlParser.h"
#include <memory.h>
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

Go to the source code of this file.

Classes

struct  ALLXMLClearTag
struct  XMLCharacterEntity
struct  XML
struct  NextToken

Defines

#define _CRT_SECURE_NO_DEPRECATE
#define INDENTCHAR   _CXML('\t')
#define XML_isSPACECHAR(ch)   ((ch==_CXML('\n'))||(ch==_CXML(' '))||(ch== _CXML('\t'))||(ch==_CXML('\r')))
#define MEMORYINCREASE   50
#define LENSTR(lpsz)   (lpsz ? xstrlen(lpsz) : 0)
#define BASE64DECODE_READ_NEXT_CHAR(c)

Typedefs

typedef enum XMLTokenTypeTag XMLTokenType
typedef struct XML XML
typedef enum Attrib Attrib
typedef enum XMLStatus XMLStatus

Enumerations

enum  XMLTokenTypeTag {
  eTokenText = 0, eTokenQuotedText, eTokenTagStart, eTokenTagEnd,
  eTokenCloseTag, eTokenEquals, eTokenDeclaration, eTokenShortHandClose,
  eTokenClear, eTokenError
}
enum  Attrib { eAttribName = 0, eAttribEquals, eAttribValue }
enum  XMLStatus { eInsideTag = 0, eOutsideTag }

Functions

void freeXMLString (XMLSTR t)
 to free the string allocated inside the "stringDup" function or the "createXMLString" function.
int mmin (const int t1, const int t2)
char myIsTextWideChar (const void *b, int len)
char * myWideCharToMultiByte (const wchar_t *s)
static FILE * xfopen (XMLCSTR filename, XMLCSTR mode)
static int xstrlen (XMLCSTR c)
static int xstrnicmp (XMLCSTR c1, XMLCSTR c2, int l)
static int xstrncmp (XMLCSTR c1, XMLCSTR c2, int l)
static int xstricmp (XMLCSTR c1, XMLCSTR c2)
static XMLSTR xstrstr (XMLCSTR c1, XMLCSTR c2)
static XMLSTR xstrcpy (XMLSTR c1, XMLCSTR c2)
static int _strnicmp (const char *c1, const char *c2, int l)
char xmltob (XMLCSTR t, char v)
int xmltoi (XMLCSTR t, int v)
long xmltol (XMLCSTR t, long v)
double xmltof (XMLCSTR t, double v)
XMLCSTR xmltoa (XMLCSTR t, XMLCSTR v)
XMLCHAR xmltoc (XMLCSTR t, const XMLCHAR v)
XMLSTR stringDup (XMLCSTR lpszData, int cbData)
 Duplicate (copy in a new allocated buffer) the source string.
XMLSTR fromXMLString (XMLCSTR s, int lo, XML *pXML)
char myTagCompare (XMLCSTR cclose, XMLCSTR copen)
static XMLCHAR getNextChar (XML *pXML)
static NextToken GetNextToken (XML *pXML, int *pcbToken, enum XMLTokenTypeTag *pType)
static void myFree (void *p)
static void * myRealloc (void *p, int newsize, int memInc, int sizeofElem)
static void CountLinesAndColumns (XMLCSTR lpXML, int nUpto, XMLResults *pResults)
static void charmemset (XMLSTR dest, XMLCHAR c, int l)

Variables

static XMLNode::XMLCharEncoding characterEncoding = XMLNode::char_encoding_UTF8
static char guessWideCharChars = 1
static char dropWhiteSpace = 1
static char removeCommentsInMiddleOfText = 1
static ALLXMLClearTag XMLClearTags []
static XMLCharacterEntity XMLEntities []
static const char XML_utf8ByteTable [256]
static const char XML_legacyByteTable [256]
static const char XML_sjisByteTable [256]
static const char XML_gb2312ByteTable [256]
static const char XML_gbk_big5_ByteTable [256]
static const char * XML_ByteTable = (const char *)XML_utf8ByteTable
static const char base64Fillchar = _CXML('=')
XMLCSTR base64EncodeTable = _CXML("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/")
const unsigned char base64DecodeTable []

Define Documentation

#define _CRT_SECURE_NO_DEPRECATE

XML.c - implementation file for basic XML parser written in ANSI C++ for portability. It works by using recursion and a node tree for breaking down the elements of an XML document.

Version:
V2.43
Author:
Frank Vanden Berghen

NOTE:

If you add "#define STRICT_PARSING", on the first line of this file the parser will see the following XML-stream: some textother text as an error. Otherwise, this tring will be equivalent to: some textother text

NOTE:

If you add "#define APPROXIMATE_PARSING" on the first line of this file the parser will see the following XML-stream: <data name="n1"> <data name="n2"> <data name="n3"> as equivalent to the following XML-stream: <data name="n1"> <data name="n2"> <data name="n3"> This can be useful for badly-formed XML-streams but prevent the use of the following XML-stream (problem is: tags at contiguous levels have the same names): <data name="n1"> <data name="n2"> <data name="n3"> </data> </data>

NOTE:

If you add "#define _XMLPARSER_NO_MESSAGEBOX_" on the first line of this file the "openFileHelper" function will always display error messages inside the console instead of inside a message-box-window. Message-box-windows are available on windows 9x/NT/2000/XP/Vista only.

Copyright (c) 2002, Business-Insight Business-Insight All rights reserved. See the file "AFPL-license.txt" about the licensing terms

Definition at line 53 of file xmlParser.cpp.

#define BASE64DECODE_READ_NEXT_CHAR (   c)
Value:
do { c=base64DecodeTable[(unsigned char)data[i++]]; }while (c==97);   \
        if(c==98){ if(xe)*xe=eXMLErrorBase64DecodeIllegalCharacter; return 0; }

Referenced by XMLParserBase64Tool::decode().

#define INDENTCHAR   _CXML('\t')

Definition at line 116 of file xmlParser.cpp.

#define LENSTR (   lpsz)    (lpsz ? xstrlen(lpsz) : 0)
#define MEMORYINCREASE   50

Definition at line 1107 of file xmlParser.cpp.

#define XML_isSPACECHAR (   ch)    ((ch==_CXML('\n'))||(ch==_CXML(' '))||(ch== _CXML('\t'))||(ch==_CXML('\r')))

Definition at line 870 of file xmlParser.cpp.

Referenced by GetNextToken(), XMLNode::guessCharEncoding(), and myTagCompare().


Typedef Documentation

typedef enum Attrib Attrib
typedef struct XML XML
typedef enum XMLStatus XMLStatus

Enumeration Type Documentation

enum Attrib
Enumerator:
eAttribName 
eAttribEquals 
eAttribValue 

Definition at line 580 of file xmlParser.cpp.

enum XMLStatus
Enumerator:
eInsideTag 
eOutsideTag 

Definition at line 589 of file xmlParser.cpp.

Enumerator:
eTokenText 
eTokenQuotedText 
eTokenTagStart 
eTokenTagEnd 
eTokenCloseTag 
eTokenEquals 
eTokenDeclaration 
eTokenShortHandClose 
eTokenClear 
eTokenError 

Definition at line 545 of file xmlParser.cpp.


Function Documentation

static int _strnicmp ( const char *  c1,
const char *  c2,
int  l 
) [inline, static]

Definition at line 345 of file xmlParser.cpp.

static void charmemset ( XMLSTR  dest,
XMLCHAR  c,
int  l 
) [inline, static]

Definition at line 1876 of file xmlParser.cpp.

static void CountLinesAndColumns ( XMLCSTR  lpXML,
int  nUpto,
XMLResults pResults 
) [static]
XMLSTR fromXMLString ( XMLCSTR  s,
int  lo,
XML pXML 
)
static XMLCHAR getNextChar ( XML pXML) [inline, static]

Definition at line 891 of file xmlParser.cpp.

References XML::lpXML, XML::nIndex, and XMLCHAR.

Referenced by CountLinesAndColumns(), and GetNextToken().

static NextToken GetNextToken ( XML pXML,
int *  pcbToken,
enum XMLTokenTypeTag pType 
) [static]
int mmin ( const int  t1,
const int  t2 
) [inline]

Definition at line 78 of file xmlParser.cpp.

Referenced by XMLNode::guessCharEncoding(), and myIsTextWideChar().

static void myFree ( void *  p) [inline, static]

Definition at line 1109 of file xmlParser.cpp.

char myIsTextWideChar ( const void *  b,
int  len 
)

Definition at line 163 of file xmlParser.cpp.

References FALSE, mmin(), and TRUE.

Referenced by XMLNode::guessCharEncoding(), and XMLNode::parseFile().

static void* myRealloc ( void *  p,
int  newsize,
int  memInc,
int  sizeofElem 
) [inline, static]

Definition at line 1110 of file xmlParser.cpp.

char myTagCompare ( XMLCSTR  cclose,
XMLCSTR  copen 
)

Definition at line 873 of file xmlParser.cpp.

References _CXML, XML_isSPACECHAR, XMLCHAR, xstrlen(), and xstrnicmp().

char* myWideCharToMultiByte ( const wchar_t *  s)

Definition at line 266 of file xmlParser.cpp.

Referenced by XMLNode::parseFile().

static FILE* xfopen ( XMLCSTR  filename,
XMLCSTR  mode 
) [inline, static]
static XMLSTR xstrcpy ( XMLSTR  c1,
XMLCSTR  c2 
) [inline, static]

Definition at line 343 of file xmlParser.cpp.

References XMLSTR.

Referenced by ToXMLStringTool::toXMLUnSafe().

static int xstricmp ( XMLCSTR  c1,
XMLCSTR  c2 
) [inline, static]
static int xstrlen ( XMLCSTR  c) [inline, static]

Definition at line 338 of file xmlParser.cpp.

Referenced by myTagCompare(), and stringDup().

static int xstrncmp ( XMLCSTR  c1,
XMLCSTR  c2,
int  l 
) [inline, static]

Definition at line 340 of file xmlParser.cpp.

Referenced by GetNextToken().

static int xstrnicmp ( XMLCSTR  c1,
XMLCSTR  c2,
int  l 
) [inline, static]

Definition at line 339 of file xmlParser.cpp.

Referenced by fromXMLString(), XMLNode::guessCharEncoding(), and myTagCompare().

static XMLSTR xstrstr ( XMLCSTR  c1,
XMLCSTR  c2 
) [inline, static]

Definition at line 342 of file xmlParser.cpp.

References XMLSTR.

Referenced by XMLNode::getChildNodeByPathNonConst().


Variable Documentation

const unsigned char base64DecodeTable[]
Initial value:
 {
    99,98,98,98,98,98,98,98,98,97,  97,98,98,97,98,98,98,98,98,98,  98,98,98,98,98,98,98,98,98,98,  
    98,98,97,98,98,98,98,98,98,98,  98,98,98,62,98,98,98,63,52,53,  54,55,56,57,58,59,60,61,98,98,  
    98,96,98,98,98, 0, 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,98,98,98,98,98,98,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,98,98,98,98,98,98,98,  98,98,98,98,98,98,98,98,98,98,  98,98,98,98,98,98,98,98,98,98,  
    98,98,98,98,98,98,98,98,98,98,  98,98,98,98,98,98,98,98,98,98,  98,98,98,98,98,98,98,98,98,98,  
    98,98,98,98,98,98,98,98,98,98,  98,98,98,98,98,98,98,98,98,98,  98,98,98,98,98,98,98,98,98,98,  
    98,98,98,98,98,98,98,98,98,98,  98,98,98,98,98,98,98,98,98,98,  98,98,98,98,98,98,98,98,98,98,  
    98,98,98,98,98,98,98,98,98,98,  98,98,98,98,98,98                                               
}

Definition at line 2781 of file xmlParser.cpp.

XMLCSTR base64EncodeTable = _CXML("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/")

Definition at line 2777 of file xmlParser.cpp.

const char base64Fillchar = _CXML('=') [static]

Definition at line 2774 of file xmlParser.cpp.

XMLNode::XMLCharEncoding characterEncoding = XMLNode::char_encoding_UTF8 [static]

Definition at line 75 of file xmlParser.cpp.

Referenced by XMLNode::setGlobalOptions(), and XMLNode::writeToFile().

char dropWhiteSpace = 1
char guessWideCharChars = 1 [static]

Definition at line 76 of file xmlParser.cpp.

Referenced by XMLNode::openFileHelper(), and XMLNode::setGlobalOptions().

const char* XML_ByteTable = (const char *)XML_utf8ByteTable [static]

Definition at line 536 of file xmlParser.cpp.

const char XML_gb2312ByteTable[256] [static]
Initial value:
{

    0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
    1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
    1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
    1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
    1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
    1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
    1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
    1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
    1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
    1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
    1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,
    2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,
    2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,
    2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,
    2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,
    2,2,2,2,2,2,2,2,1,1,1,1,1,1,1,1 
}

Definition at line 496 of file xmlParser.cpp.

Referenced by XMLNode::setGlobalOptions().

const char XML_gbk_big5_ByteTable[256] [static]
Initial value:
{
    
    0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
    1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
    1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
    1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
    1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
    1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
    1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
    1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
    1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,
    2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,
    2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,
    2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,
    2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,
    2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,
    2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,
    2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1 
}

Definition at line 516 of file xmlParser.cpp.

Referenced by XMLNode::setGlobalOptions().

const char XML_legacyByteTable[256] [static]
Initial value:
{
    0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
    1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
    1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
    1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
    1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
    1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
}

Definition at line 467 of file xmlParser.cpp.

Referenced by XMLNode::setGlobalOptions().

const char XML_sjisByteTable[256] [static]
Initial value:
{
    
    0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
    1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
    1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
    1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
    1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
    1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
    1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
    1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
    1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,
    2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,
    1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
    1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
    1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
    1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
    2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,
    1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1 
}

Definition at line 476 of file xmlParser.cpp.

Referenced by XMLNode::setGlobalOptions().

const char XML_utf8ByteTable[256] [static]
Initial value:
{
    
    0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
    1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
    1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
    1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
    1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
    1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
    1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
    1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
    1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
    1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
    1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
    1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
    1,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,
    2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,
    3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
    4,4,4,4,4,1,1,1,1,1,1,1,1,1,1,1 
}

Definition at line 447 of file xmlParser.cpp.

Referenced by XMLNode::setGlobalOptions().

Initial value:
{
    {    _CXML("<![CDATA["),9,  _CXML("]]>")      },
    {    _CXML("<!DOCTYPE"),9,  _CXML(">")        },
    {    _CXML("<!--")     ,4,  _CXML("-->")      },
    {    _CXML("<PRE>")    ,5,  _CXML("</PRE>")   },

    {    NULL              ,0,  NULL           }
}

Definition at line 88 of file xmlParser.cpp.

Referenced by GetNextToken().

Initial value:
{
    { _CXML("&amp;" ), 5, _CXML('&' )},
    { _CXML("&lt;"  ), 4, _CXML('<' )},
    { _CXML("&gt;"  ), 4, _CXML('>' )},
    { _CXML("&quot;"), 6, _CXML('\"')},
    { _CXML("&apos;"), 6, _CXML('\'')},
    { NULL           , 0, '\0'    }
}

Definition at line 103 of file xmlParser.cpp.

Referenced by fromXMLString(), ToXMLStringTool::lengthXMLString(), and ToXMLStringTool::toXMLUnSafe().