TiXmlNode* TiXmlNode::Identify( const char* p, TiXmlEncoding encoding ) { TiXmlNode* returnNode = 0; p = SkipWhiteSpace( p, encoding ); if( !p || !*p || *p != '<' ) { return 0; } p = SkipWhiteSpace( p, encoding ); if ( !p || !*p ) { return 0; } // What is this thing? // - Elements start with a letter or underscore, but xml is reserved. // - Comments: <!-- // - Decleration: <?xml // - Everthing else is unknown to tinyxml. // const char* xmlHeader = { "<?xml" }; const char* commentHeader = { "<!--" }; const char* dtdHeader = { "<!" }; const char* cdataHeader = { "<![CDATA[" }; if ( StringEqual( p, xmlHeader, true, encoding ) ) { #ifdef DEBUG_PARSER TIXML_LOG( "XML parsing Declaration\n" ); #endif returnNode = new TiXmlDeclaration(); } else if ( StringEqual( p, commentHeader, false, encoding ) ) { #ifdef DEBUG_PARSER TIXML_LOG( "XML parsing Comment\n" ); #endif returnNode = new TiXmlComment(); } else if ( StringEqual( p, cdataHeader, false, encoding ) ) { #ifdef DEBUG_PARSER TIXML_LOG( "XML parsing CDATA\n" ); #endif TiXmlText* text = new TiXmlText( "" ); text->SetCDATA( true ); returnNode = text; } else if ( StringEqual( p, dtdHeader, false, encoding ) ) { #ifdef DEBUG_PARSER TIXML_LOG( "XML parsing Unknown(1)\n" ); #endif returnNode = new TiXmlUnknown(); } else if ( IsAlpha( *(p+1), encoding ) || *(p+1) == '_' ) { #ifdef DEBUG_PARSER TIXML_LOG( "XML parsing Element\n" ); #endif returnNode = new TiXmlElement( "" ); } else { #ifdef DEBUG_PARSER TIXML_LOG( "XML parsing Unknown(2)\n" ); #endif returnNode = new TiXmlUnknown(); } if ( returnNode ) { // Set the parent, so it can report errors returnNode->parent = this; } return returnNode; }
TiXmlNode* TiXmlNode::Identify( const TIXML_CHAR* p, TiXmlEncoding encoding ) { TiXmlNode* returnNode = 0; p = SkipWhiteSpace( p, encoding ); if( !p || !*p || *p != _TIXML_L('<') ) { return 0; } TiXmlDocument* doc = GetDocument(); p = SkipWhiteSpace( p, encoding ); if ( !p || !*p ) { return 0; } // What is this thing? // - Elements start with a letter or underscore, but xml is reserved. // - Comments: <!-- // - Decleration: <?xml // - Everthing else is unknown to tinyxml. // const TIXML_CHAR* xmlHeader = { _TIXML_L("<?xml") }; const TIXML_CHAR* commentHeader = { _TIXML_L("<!--") }; const TIXML_CHAR* dtdHeader = { _TIXML_L("<!") }; const TIXML_CHAR* cdataHeader = { _TIXML_L("<![CDATA[") }; if ( StringEqual( p, xmlHeader, true, encoding ) ) { #ifdef DEBUG_PARSER TIXML_LOG( _TIXML_L("XML parsing Declaration\n") ); #endif returnNode = new TiXmlDeclaration(); } else if ( StringEqual( p, commentHeader, false, encoding ) ) { #ifdef DEBUG_PARSER TIXML_LOG( _TIXML_L("XML parsing Comment\n") ); #endif returnNode = new TiXmlComment(); } else if ( StringEqual( p, cdataHeader, false, encoding ) ) { #ifdef DEBUG_PARSER TIXML_LOG( _TIXML_L("XML parsing CDATA\n") ); #endif TiXmlText* text = new TiXmlText( _TIXML_L("") ); text->SetCDATA( true ); returnNode = text; } else if ( StringEqual( p, dtdHeader, false, encoding ) ) { #ifdef DEBUG_PARSER TIXML_LOG( _TIXML_L("XML parsing Unknown(1)\n") ); #endif returnNode = new TiXmlUnknown(); } else if ( IsAlpha( *(p+1), encoding ) || *(p+1) == _TIXML_L('_') ) { #ifdef DEBUG_PARSER TIXML_LOG( _TIXML_L("XML parsing Element\n") ); #endif returnNode = new TiXmlElement( _TIXML_L("") ); } else { #ifdef DEBUG_PARSER TIXML_LOG( _TIXML_L("XML parsing Unknown(2)\n") ); #endif returnNode = new TiXmlUnknown(); } if ( returnNode ) { // Set the parent, so it can report errors returnNode->parent = this; } else { if ( doc ) doc->SetError( TIXML_ERROR_OUT_OF_MEMORY, 0, 0, TIXML_ENCODING_UNKNOWN ); } return returnNode; }
TiXmlNode* TiXmlNode::Identify( const char* p ) { TiXmlNode* returnNode = 0; p = SkipWhiteSpace( p ); if( !p || !*p || *p != '<' ) { return 0; } TiXmlDocument* doc = GetDocument(); p = SkipWhiteSpace( p ); if ( !p || !*p ) { return 0; } // What is this thing? // - Elements start with a letter or underscore, but xml is reserved. // - Comments: <!-- // - Decleration: <?xml // - Everthing else is unknown to tinyxml. // const char* xmlHeader = { "<?xml" }; const char* commentHeader = { "<!--" }; if ( StringEqual( p, xmlHeader, true ) ) { #ifdef DEBUG_PARSER TIXML_LOG( "XML parsing Declaration\n" ); #endif returnNode = new TiXmlDeclaration(); } else if ( isalpha( *(p+1) ) || *(p+1) == '_' ) { #ifdef DEBUG_PARSER TIXML_LOG( "XML parsing Element\n" ); #endif returnNode = new TiXmlElement( "" ); } else if ( StringEqual( p, commentHeader, false ) ) { #ifdef DEBUG_PARSER TIXML_LOG( "XML parsing Comment\n" ); #endif returnNode = new TiXmlComment(); } else { #ifdef DEBUG_PARSER TIXML_LOG( "XML parsing Unknown\n" ); #endif returnNode = new TiXmlUnknown(); } if ( returnNode ) { // Set the parent, so it can report errors returnNode->parent = this; } else { if ( doc ) doc->SetError( TIXML_ERROR_OUT_OF_MEMORY, 0, 0 ); } return returnNode; }
// We're expecting a tag; identify what kind here and allocate the // appropriate type of node (but don't parse yet). We'll return null if // we can't find a "<" as the next non-whitespace character, or if we // find the "<" but it is followed by nothing but whitespace. Note that // we're only looking at the beginning of the tag, we won't check to see // if it is terminated properly. TiXmlNode* TiXmlNode::Identify( const char* p, TiXmlEncoding encoding ) { TiXmlNode* returnNode = 0; p = SkipWhiteSpace( p, encoding ); if( !p || !*p || *p != '<' ) { return 0; // couldn't find the tag-opening "<" } TiXmlDocument* doc = GetDocument(); p = SkipWhiteSpace( p, encoding ); if ( !p || !*p ) { return 0; // a lone "<" at the end of the document } // What is this thing? // - Elements: < X where X is a letter or underscore; // white space optional between "<" and "X". // - Comments: <!-- // - Declaration: <?xml // - CDATA Text: <![CDATA[ // - All other tags are unknown to tinyxml. // const char* xmlHeader = { "<?xml" }; const char* commentHeader = { "<!--" }; const char* dtdHeader = { "<!" }; // treated as "unknown" const char* cdataHeader = { "<![CDATA[" }; if ( StringEqual( p, xmlHeader, true, encoding ) ) { #ifdef DEBUG_PARSER TIXML_LOG( "XML parsing Declaration\n" ); #endif returnNode = new TiXmlDeclaration(); } else if ( StringEqual( p, commentHeader, false, encoding ) ) { #ifdef DEBUG_PARSER TIXML_LOG( "XML parsing Comment\n" ); #endif returnNode = new TiXmlComment(); } else if ( StringEqual( p, cdataHeader, false, encoding ) ) { #ifdef DEBUG_PARSER TIXML_LOG( "XML parsing CDATA\n" ); #endif TiXmlText* text = new TiXmlText( "" ); text->SetCDATA( true ); returnNode = text; } else if ( StringEqual( p, dtdHeader, false, encoding ) ) { #ifdef DEBUG_PARSER TIXML_LOG( "XML parsing Unknown(1)\n" ); #endif returnNode = new TiXmlUnknown(); } else if ( IsAlpha( *(p+1), encoding ) || *(p+1) == '_' ) { #ifdef DEBUG_PARSER TIXML_LOG( "XML parsing Element\n" ); #endif returnNode = new TiXmlElement( "" ); } else { #ifdef DEBUG_PARSER TIXML_LOG( "XML parsing Unknown(2)\n" ); #endif returnNode = new TiXmlUnknown(); } if ( returnNode ) { // Set the parent, so it can report errors returnNode->parent = this; } else { if ( doc ) doc->SetError( TIXML_ERROR_OUT_OF_MEMORY, 0, 0, TIXML_ENCODING_UNKNOWN ); } return returnNode; }