Remove unneeded cast, reduce duplication, move declarations to their first use.
diff --git a/tinyxml2.cpp b/tinyxml2.cpp
index 53d78bd..0e1386d 100755
--- a/tinyxml2.cpp
+++ b/tinyxml2.cpp
@@ -114,12 +114,12 @@
 

 char* StrPair::ParseName( char* p )

 {

-    char* start = p;

-

-    if ( !start || !(*start) ) {

+    if ( !p || !(*p) ) {

         return 0;

     }

 

+    char* const start = p;

+

     while( *p && ( p == start ? XMLUtil::IsNameStartChar( *p ) : XMLUtil::IsNameChar( *p ) )) {

         ++p;

     }

@@ -479,8 +479,7 @@
 

 char* XMLDocument::Identify( char* p, XMLNode** node )

 {

-    XMLNode* returnNode = 0;

-    char* start = p;

+    char* const start = p;

     p = XMLUtil::SkipWhiteSpace( p );

     if( !p || !*p ) {

         return p;

@@ -509,6 +508,7 @@
 #if defined(_MSC_VER)

 #pragma warning (pop)

 #endif

+    XMLNode* returnNode = 0;

     if ( XMLUtil::StringEqual( p, xmlHeader, xmlHeaderLen ) ) {

         returnNode = new (_commentPool.Alloc()) XMLDeclaration( this );

         returnNode->_memPool = &_commentPool;

@@ -693,7 +693,7 @@
         addThis->_next = 0;

     }

     addThis->_parent = this;

-     return addThis;

+    return addThis;

 }

 

 

@@ -823,7 +823,7 @@
         // We read the end tag. Return it to the parent.

         if ( ele && ele->ClosingType() == XMLElement::CLOSING ) {

             if ( parentEnd ) {

-                *parentEnd = static_cast<XMLElement*>(node)->_value;

+                *parentEnd = ele->_value;

             }

 			node->_memPool->SetTracked();	// created and then immediately deleted.

             DeleteNode( node );

@@ -833,20 +833,22 @@
         // Handle an end tag returned to this level.

         // And handle a bunch of annoying errors.

         if ( ele ) {

+            bool mismatch = false;

             if ( endTag.Empty() && ele->ClosingType() == XMLElement::OPEN ) {

-                _document->SetError( XML_ERROR_MISMATCHED_ELEMENT, node->Value(), 0 );

-                p = 0;

+                mismatch = true;

             }

             else if ( !endTag.Empty() && ele->ClosingType() != XMLElement::OPEN ) {

-                _document->SetError( XML_ERROR_MISMATCHED_ELEMENT, node->Value(), 0 );

-                p = 0;

+                mismatch = true;

             }

             else if ( !endTag.Empty() ) {

                 if ( !XMLUtil::StringEqual( endTag.GetStr(), node->Value() )) {

-                    _document->SetError( XML_ERROR_MISMATCHED_ELEMENT, node->Value(), 0 );

-                    p = 0;

+                    mismatch = true;

                 }

             }

+            if ( mismatch ) {

+                _document->SetError( XML_ERROR_MISMATCHED_ELEMENT, node->Value(), 0 );

+                p = 0;

+            }

         }

         if ( p == 0 ) {

             DeleteNode( node );