Example #1
0
	XMLNode* XMLText::ShallowClone( XMLDocument* doc ) const
	{
		if ( !doc ) {
			doc = _document;
		}
		XMLText* text = doc->NewText( Value() );	// fixme: this will always allocate memory. Intern?
		text->SetCData( this->CData() );
		return text;
	}
Example #2
0
	char* XMLDocument::Identify( char* p, XMLNode** node )
	{
		XMLNode* returnNode = 0;
		char* start = p;
		p = XMLUtil::SkipWhiteSpace( p );
		if( !p || !*p ) {
			return p;
		}

		// What is this thing?
		// - Elements start with a letter or underscore, but xml is reserved.
		// - Comments: <!--
		// - Declaration: <?
		// - Everything else is unknown to tinyxml.
		//

		static const char* xmlHeader		= { "<?" };
		static const char* commentHeader	= { "<!--" };
		static const char* dtdHeader		= { "<!" };
		static const char* cdataHeader		= { "<![CDATA[" };
		static const char* elementHeader	= { "<" };	// and a header for everything else; check last.

		static const int xmlHeaderLen		= 2;
		static const int commentHeaderLen	= 4;
		static const int dtdHeaderLen		= 2;
		static const int cdataHeaderLen		= 9;
		static const int elementHeaderLen	= 1;

#if defined(_MSC_VER)
#pragma warning ( push )
#pragma warning ( disable : 4127 )
#endif
		TIXMLASSERT( sizeof( XMLComment ) == sizeof( XMLUnknown ) );		// use same memory pool
		TIXMLASSERT( sizeof( XMLComment ) == sizeof( XMLDeclaration ) );	// use same memory pool
#if defined(_MSC_VER)
#pragma warning (pop)
#endif
		if ( XMLUtil::StringEqual( p, xmlHeader, xmlHeaderLen ) ) {
			returnNode = new (_commentPool.Alloc()) XMLDeclaration( this );
			returnNode->_memPool = &_commentPool;
			p += xmlHeaderLen;
		}
		else if ( XMLUtil::StringEqual( p, commentHeader, commentHeaderLen ) ) {
			returnNode = new (_commentPool.Alloc()) XMLComment( this );
			returnNode->_memPool = &_commentPool;
			p += commentHeaderLen;
		}
		else if ( XMLUtil::StringEqual( p, cdataHeader, cdataHeaderLen ) ) {
			XMLText* text = new (_textPool.Alloc()) XMLText( this );
			returnNode = text;
			returnNode->_memPool = &_textPool;
			p += cdataHeaderLen;
			text->SetCData( true );
		}
		else if ( XMLUtil::StringEqual( p, dtdHeader, dtdHeaderLen ) ) {
			returnNode = new (_commentPool.Alloc()) XMLUnknown( this );
			returnNode->_memPool = &_commentPool;
			p += dtdHeaderLen;
		}
		else if ( XMLUtil::StringEqual( p, elementHeader, elementHeaderLen ) ) {
			returnNode = new (_elementPool.Alloc()) XMLElement( this );
			returnNode->_memPool = &_elementPool;
			p += elementHeaderLen;
		}
		else {
			returnNode = new (_textPool.Alloc()) XMLText( this );
			returnNode->_memPool = &_textPool;
			p = start;	// Back it up, all the text counts.
		}

		*node = returnNode;
		return p;
	}