当前位置: 首页>>代码示例>>C++>>正文


C++ TTiXmlNode::ToDeclaration方法代码示例

本文整理汇总了C++中TTiXmlNode::ToDeclaration方法的典型用法代码示例。如果您正苦于以下问题:C++ TTiXmlNode::ToDeclaration方法的具体用法?C++ TTiXmlNode::ToDeclaration怎么用?C++ TTiXmlNode::ToDeclaration使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在TTiXmlNode的用法示例。


在下文中一共展示了TTiXmlNode::ToDeclaration方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: Parse

const char* TTiXmlDocument::Parse( const char* p, TTiXmlParsingData* prevData, TTiXmlEncoding encoding )
{
	ClearError();

	// Parse away, at the document level. Since a document
	// contains nothing but other tags, most of what happens
	// here is skipping white space.
	if ( !p || !*p )
	{
		SetError( TTiXml_ERROR_DOCUMENT_EMPTY, 0, 0, TTiXml_ENCODING_UNKNOWN );
		return 0;
	}

	// Note that, for a document, this needs to come
	// before the while space skip, so that parsing
	// starts from the pointer we are given.
	location.Clear();
	if ( prevData )
	{
		location.row = prevData->cursor.row;
		location.col = prevData->cursor.col;
	}
	else
	{
		location.row = 0;
		location.col = 0;
	}
	TTiXmlParsingData data( p, TabSize(), location.row, location.col );
	location = data.Cursor();

	if ( encoding == TTiXml_ENCODING_UNKNOWN )
	{
		// Check for the Microsoft UTF-8 lead bytes.
		const unsigned char* pU = (const unsigned char*)p;
		if (	*(pU+0) && *(pU+0) == TTiXml_UTF_LEAD_0
			 && *(pU+1) && *(pU+1) == TTiXml_UTF_LEAD_1
			 && *(pU+2) && *(pU+2) == TTiXml_UTF_LEAD_2 )
		{
			encoding = TTiXml_ENCODING_UTF8;
			useMicrosoftBOM = true;
		}
	}

    p = SkipWhiteSpace( p, encoding );
	if ( !p )
	{
		SetError( TTiXml_ERROR_DOCUMENT_EMPTY, 0, 0, TTiXml_ENCODING_UNKNOWN );
		return 0;
	}

	while ( p && *p )
	{
		TTiXmlNode* node = Identify( p, encoding );
		if ( node )
		{
			p = node->Parse( p, &data, encoding );
			LinkEndChild( node );
		}
		else
		{
			break;
		}

		// Did we get encoding info?
		if (    encoding == TTiXml_ENCODING_UNKNOWN
			 && node->ToDeclaration() )
		{
			TTiXmlDeclaration* dec = node->ToDeclaration();
			const char* enc = dec->Encoding();
			assert( enc );

			if ( *enc == 0 )
				encoding = TTiXml_ENCODING_UTF8;
			else if ( StringEqual( enc, "UTF-8", true, TTiXml_ENCODING_UNKNOWN ) )
				encoding = TTiXml_ENCODING_UTF8;
			else if ( StringEqual( enc, "UTF8", true, TTiXml_ENCODING_UNKNOWN ) )
				encoding = TTiXml_ENCODING_UTF8;	// incorrect, but be nice
			else 
				encoding = TTiXml_ENCODING_LEGACY;
		}

		p = SkipWhiteSpace( p, encoding );
	}

	// Was this empty?
	if ( !firstChild ) {
		SetError( TTiXml_ERROR_DOCUMENT_EMPTY, 0, 0, encoding );
		return 0;
	}

	// All is well.
	return p;
}
开发者ID:caoguoping,项目名称:warCraft,代码行数:93,代码来源:tinyxmlparser.cpp


注:本文中的TTiXmlNode::ToDeclaration方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。