⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mcbxml.c

📁 brew 平台xml解析
💻 C
📖 第 1 页 / 共 5 页
字号:
        * First check whether the token is in the clear tag list (meaning it 
		* does not need formatting).
        *********************************************************************
        */
		n = 0;

		while(TRUE)
		{
           /*
            *****************************************************************
            * Obtain the name of the open part of the clear tag
            *****************************************************************
            */
			lpszOpen = pXML->pClrTags[n].lpszOpen;

			if (lpszOpen)
			{
               /*
                *************************************************************
                * Compare the open tag with the current token
                *************************************************************
                */
				cbOpen = _tcslen(lpszOpen);

				if (_tcsnicmp(lpszOpen, result.pStr, cbOpen) == 0)
				{
					result.pClr = &pXML->pClrTags[n];
					pXML->nIndex += cbOpen-1;
					*pType  = eTokenClear;
					return result;
				}

				n++;
			}
			else
			{
				break;
			}
		}

       /*
        *********************************************************************
        * If we didn't find a clear tag then check for standard tokens
        *********************************************************************
        */
		chTemp = 0;

		lpXML = pXML->lpXML;
		
		switch(ch)
		{
       /*
        *********************************************************************
        * Check for quotes
        *********************************************************************
        */
		case _T('\''):
		case _T('\"'):

           /*
            *****************************************************************
            * Type of token
            *****************************************************************
            */
			*pType = eTokenQuotedText;

			chTemp = ch;

           /*
            *****************************************************************
            * Set the size
            *****************************************************************
            */			
			nSize = 1;

			nFoundMatch = FALSE;

           /*
            *****************************************************************
            * Search through the string to find a matching quote
            *****************************************************************
            */
			while(ch = McbGetNextChar(pXML))
			{
				nSize++;

				if (ch == chTemp)
				{
					nFoundMatch = TRUE;
					break;
				}
			}

           /*
            *****************************************************************
            * If we failed to find a matching quote
            *****************************************************************
            */
			if (nFoundMatch == FALSE)
			{
               /*
                *************************************************************
                * Indicate error
                *************************************************************
                */
				pXML->error = eXMLErrorNoMatchingQuote;				
				*pType = eTokenError;
			}

			/* MCB 4.02.2002 */
			if (McbFindNonWhiteSpace(pXML))
			{
				pXML->nIndex--;
			}

			break;

       /*
        *********************************************************************
        * Equals (used with attribute values)
        *********************************************************************
        */
		case _T('='):
			nSize = 1;
			*pType = eTokenEquals;
			break;

       /*
        *********************************************************************
        * Close tag
        *********************************************************************
        */
		case _T('>'):
			nSize = 1;
			*pType = eTokenCloseTag;
			break;

       /*
        *********************************************************************
        * Check for tag start and tag end
        *********************************************************************
        */
		case _T('<'):

           /*
            *****************************************************************
            * Peek at the next character to see if we have an end tag '</',
			* or an xml declaration '<?'
            *****************************************************************
            */
			chTemp = pXML->lpXML[pXML->nIndex];

           /*
            *****************************************************************
            * If we have a tag end...
            *****************************************************************
            */
			if (chTemp == _T('/'))
			{
               /*
                *************************************************************
                * Set the type and ensure we point at the next character 
                *************************************************************
                */
				McbGetNextChar(pXML);
				*pType = eTokenTagEnd;
				nSize = 2;
			}
           /*
            *****************************************************************
            * If we have an XML declaration tag
            *****************************************************************
            */
			else if (chTemp == _T('?'))
			{
               /*
                *************************************************************
                * Set the type and ensure we point at the next character 
                *************************************************************
                */
				McbGetNextChar(pXML);
				*pType = eTokenDeclaration;
				nSize = 2;
			}
           /*
            *****************************************************************
            * Otherwise we must have a start tag
            *****************************************************************
            */
            else 
			{
				*pType = eTokenTagStart;
				nSize = 1;
			}
			break;

       /*
        *********************************************************************
        * Check to see if we have a short hand type end tag ('/>').
        *********************************************************************
        */
		case _T('/'):
		   /*
            *****************************************************************
            * Peek at the next character to see if we have an end tag '</'
			* or an xml declaration '<?'
            *****************************************************************
            */
			chTemp = pXML->lpXML[pXML->nIndex];

           /*
            *****************************************************************
            * If we have a short hand end tag...
            *****************************************************************
            */
			if (chTemp == _T('>'))
			{
               /*
                *************************************************************
                * Set the type and ensure we point at the next character 
                *************************************************************
                */
				McbGetNextChar(pXML);
				*pType = eTokenShortHandClose;
				nSize = 2;
				break;
			}

           /*
            *****************************************************************
            * If we haven't found a short hand closing tag then drop into the
			* text process
            *****************************************************************
            */

       /*
        *********************************************************************
        * Other characters
        *********************************************************************
        */
		default:
			nIsText = TRUE;
		}

       /*
        *********************************************************************
        * If this is a TEXT node
        *********************************************************************
        */
		if (nIsText)
		{
           /*
            *****************************************************************
            * Indicate we are dealing with text
            *****************************************************************
            */
			*pType = eTokenText;

			nSize = 1;
			nExit = FALSE;

			while((nExit == FALSE) && (ch = McbGetNextChar(pXML)))
			{
                switch(ch)
                {
               /*
                *************************************************************
                * Break when we find white space
                *************************************************************
                */
                case _T('\n'):
                case _T(' '):
                case _T('\t'):
                case _T('\r'):
					nExit = TRUE;
                    break;

               /*
                *************************************************************
                * If we find a slash then this maybe text or a short hand end
				* tag.
                *************************************************************
                */
				case _T('/'):
                   /*
                    *********************************************************
                    * Peek at the next character to see it we have short hand
					* end tag
                    *********************************************************
                    */
					chTemp = pXML->lpXML[pXML->nIndex];

                   /*
                    *********************************************************
                    * If we found a short hand end tag then we need to exit 
					* the loop
                    *********************************************************
                    */
					if (chTemp == _T('>'))
					{
						pXML->nIndex--; /* MCB 03.02.2002 */
						nExit = TRUE;
					}
					else
					{
						nSize++;
					}
					break;

               /*
                *************************************************************
                * Break when we find a terminator and decrement the index and
				* column count so that we are pointing at the right character
				* the next time we are called.
                *************************************************************
                */
				case _T('<'):
				case _T('>'):
				case _T('='):
					pXML->nIndex--;					
					nExit = TRUE;
					break;

				case 0:
					nExit = TRUE;
					break;

				default:
					nSize++;
                }
			}
		}

		*pcbToken = nSize;
	}
   /*
    *************************************************************************
    * If we failed to obtain a valid character
    *************************************************************************
    */
    else 
    {
   		*pcbToken = 0;
		*pType = eTokenError;
    }

	return result;

}/* McbGetNextToken */

/**
 ****************************************************************************
 * <P> Parse XML errors into a user friendly string.  </P>
 *
 * @methodName  McbGetError
 *
 * @param       error		
 *
 * @return      LPCTSTR
 *
 * @exception   none
 *
 * @author      Martyn C Brown
 *
 * @changeHistory  
 *	19th August    	2001	 - 	(V1.0) Creation (MCB)
 ****************************************************************************
 */
LPCTSTR McbGetError(McbXMLError error)
{
	LPCTSTR lpszErr = _T("Unknown");
	int n;

   /*
    *************************************************************************
    * Structure for errors array
    *************************************************************************
    */
	typedef struct McbErrorList
	{
		enum McbXMLError err;
		LPCTSTR lpszErr;
	} McbErrorList;

   /*
    *************************************************************************
    * Static array containing helpful error text.
    *************************************************************************
    */
	static struct McbErrorList errs[] = 
	{
		{ eXMLErrorNone,				_T("No error")					},
		{ eXMLErrorEmpty,				_T("No XML data")				},
		{ eXMLErrorFirstNotStartTag,	_T("First token not start tag")	},
		{ eXMLErrorMissingTagName,		_T("Missing start tag name")	},
		{ eXMLErrorMissingEndTagName,	_T("Missing end tag name")		},
		{ eXMLErrorNoMatchingQuote,		_T("Unmatched quote")			},
		{ eXMLErrorUnmatchedEndTag,		_T("Unmatched end tag")			},
		{ eXMLErrorUnexpectedToken,		_T("Unexpected token found")	},
		{ eXMLErrorInvalidTag,			_T("Invalid tag found")			},
		{ eXMLErrorNoElements,			_T("No elements found")			},
		{ 0,							NULL							}
	};

   /*
    *************************************************************************
    * Iterate through the list of errors to find a matching error
    *************************************************************************
    */
	for(n = 0; errs[n].lpszErr; n++)
	{
		if (errs[n].err == error)
		{
			lpszErr = errs[n].lpszErr;
			break;
		}
	}

	return lpszErr;	

}/* McbGetError */

/**
 ****************************************************************************
 * <P> Delete memory associated with a text node.   </P>
 *
 * @methodName  McbDeleteText
 *
 * @param       *pText		
 *
 * @return      void
 *
 * @exception   none
 *
 * @author      Martyn C Brown
 *
 * @changeHistory  
 *	20th August    	2001	 - 	(V1.0) Creation (MCB)
 ****************************************************************************
 */
void McbDeleteText(McbXMLText *pText)
{
	assert(pText);

	if (pText->lpszValue)
	{
		free(pText->lpszValue);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -