Index: branches/world_entities/src/lib/tinyxml/tinyxml.cc
===================================================================
--- branches/world_entities/src/lib/tinyxml/tinyxml.cc	(revision 5797)
+++ branches/world_entities/src/lib/tinyxml/tinyxml.cc	(revision 5817)
@@ -101,5 +101,11 @@
 			// Below 32 is symbolic.
 			char buf[ 32 ];
-			sprintf( buf, "&#x%02X;", (unsigned) ( c & 0xff ) );
+			
+			#if defined(TIXML_SNPRINTF)		
+				TIXML_SNPRINTF( buf, sizeof(buf), "&#x%02X;", (unsigned) ( c & 0xff ) );
+			#else
+				sprintf( buf, "&#x%02X;", (unsigned) ( c & 0xff ) );
+			#endif		
+
 			//*ME:	warning C4267: convert 'size_t' to 'int'
 			//*ME:	Int-Cast to make compiler happy ...
@@ -319,5 +325,5 @@
 	for ( node = firstChild; node; node = node->next )
 	{
-		if ( node->SValue() == _value )
+		if ( strcmp( node->Value(), _value ) == 0 )
 			return node;
 	}
@@ -331,5 +337,5 @@
 	for ( node = firstChild; node; node = node->next )
 	{
-		if ( node->SValue() == _value )
+		if ( strcmp( node->Value(), _value ) == 0 )
 			return node;
 	}
@@ -343,5 +349,5 @@
 	for ( node = lastChild; node; node = node->prev )
 	{
-		if ( node->SValue() == _value )
+		if ( strcmp( node->Value(), _value ) == 0 )
 			return node;
 	}
@@ -354,5 +360,5 @@
 	for ( node = lastChild; node; node = node->prev )
 	{
-		if ( node->SValue() == _value )
+		if ( strcmp( node->Value(), _value ) == 0 )
 			return node;
 	}
@@ -417,5 +423,5 @@
 	for ( node = next; node; node = node->next )
 	{
-		if ( node->SValue() == _value )
+		if ( strcmp( node->Value(), _value ) == 0 )
 			return node;
 	}
@@ -428,5 +434,5 @@
 	for ( node = next; node; node = node->next )
 	{
-		if ( node->SValue() == _value )
+		if ( strcmp( node->Value(), _value ) == 0 )
 			return node;
 	}
@@ -439,5 +445,5 @@
 	for ( node = prev; node; node = node->prev )
 	{
-		if ( node->SValue() == _value )
+		if ( strcmp( node->Value(), _value ) == 0 )
 			return node;
 	}
@@ -450,5 +456,5 @@
 	for ( node = prev; node; node = node->prev )
 	{
-		if ( node->SValue() == _value )
+		if ( strcmp( node->Value(), _value ) == 0 )
 			return node;
 	}
@@ -716,5 +722,9 @@
 {	
 	char buf[64];
-	sprintf( buf, "%d", val );
+	#if defined(TIXML_SNPRINTF)		
+		TIXML_SNPRINTF( buf, sizeof(buf), "%d", val );
+	#else
+		sprintf( buf, "%d", val );
+	#endif
 	SetAttribute( name, buf );
 }
@@ -724,5 +734,9 @@
 {	
 	char buf[256];
-	sprintf( buf, "%f", val );
+	#if defined(TIXML_SNPRINTF)		
+		TIXML_SNPRINTF( buf, sizeof(buf), "%f", val );
+	#else
+		sprintf( buf, "%f", val );
+	#endif
 	SetAttribute( name, buf );
 }
@@ -866,7 +880,21 @@
 
 
+const char* TiXmlElement::GetText() const
+{
+	const TiXmlNode* child = this->FirstChild();
+	if ( child ) {
+		const TiXmlText* childText = child->ToText();
+		if ( childText ) {
+			return childText->Value();
+		}
+	}
+	return 0;
+}
+
+
 TiXmlDocument::TiXmlDocument() : TiXmlNode( TiXmlNode::DOCUMENT )
 {
 	tabsize = 4;
+	useMicrosoftBOM = false;
 	ClearError();
 }
@@ -875,4 +903,5 @@
 {
 	tabsize = 4;
+	useMicrosoftBOM = false;
 	value = documentName;
 	ClearError();
@@ -884,4 +913,5 @@
 {
 	tabsize = 4;
+	useMicrosoftBOM = false;
     value = documentName;
 	ClearError();
@@ -942,5 +972,6 @@
 	value = filename;
 
-	FILE* file = fopen( value.c_str (), "r" );
+	// reading in binary mode so that tinyxml can normalize the EOL
+	FILE* file = fopen( value.c_str (), "rb" );	
 
 	if ( file )
@@ -964,12 +995,81 @@
 		data.reserve( length );
 
-		const int BUF_SIZE = 2048;
-		char buf[BUF_SIZE];
-
-		while( fgets( buf, BUF_SIZE, file ) )
+		// Subtle bug here. TinyXml did use fgets. But from the XML spec:
+		// 2.11 End-of-Line Handling
+		// <snip>
+		// <quote>
+		// ...the XML processor MUST behave as if it normalized all line breaks in external 
+		// parsed entities (including the document entity) on input, before parsing, by translating 
+		// both the two-character sequence #xD #xA and any #xD that is not followed by #xA to 
+		// a single #xA character.
+		// </quote>
+		//
+		// It is not clear fgets does that, and certainly isn't clear it works cross platform. 
+		// Generally, you expect fgets to translate from the convention of the OS to the c/unix
+		// convention, and not work generally.
+
+		/*
+		while( fgets( buf, sizeof(buf), file ) )
 		{
 			data += buf;
 		}
+		*/
+
+		char* buf = new char[ length+1 ];
+		buf[0] = 0;
+
+		if ( fread( buf, length, 1, file ) != 1 ) {
+		//if ( fread( buf, 1, length, file ) != (size_t)length ) {
+			SetError( TIXML_ERROR_OPENING_FILE, 0, 0, TIXML_ENCODING_UNKNOWN );
+			fclose( file );
+			return false;
+		}
 		fclose( file );
+
+		const char* lastPos = buf;
+		const char* p = buf;
+
+		buf[length] = 0;
+		while( *p ) {
+			assert( p < (buf+length) );
+			if ( *p == 0xa ) {
+				// Newline character. No special rules for this. Append all the characters
+				// since the last string, and include the newline.
+				data.append( lastPos, p-lastPos+1 );	// append, include the newline
+				++p;									// move past the newline
+				lastPos = p;							// and point to the new buffer (may be 0)
+				assert( p <= (buf+length) );
+			}
+			else if ( *p == 0xd ) {
+				// Carriage return. Append what we have so far, then
+				// handle moving forward in the buffer.
+				if ( (p-lastPos) > 0 ) {
+					data.append( lastPos, p-lastPos );	// do not add the CR
+				}
+				data += (char)0xa;						// a proper newline
+
+				if ( *(p+1) == 0xa ) {
+					// Carriage return - new line sequence
+					p += 2;
+					lastPos = p;
+					assert( p <= (buf+length) );
+				}
+				else {
+					// it was followed by something else...that is presumably characters again.
+					++p;
+					lastPos = p;
+					assert( p <= (buf+length) );
+				}
+			}
+			else {
+				++p;
+			}
+		}
+		// Handle any left over characters.
+		if ( p-lastPos ) {
+			data.append( lastPos, p-lastPos );
+		}		
+		delete [] buf;
+		buf = 0;
 
 		Parse( data.c_str(), 0, encoding );
@@ -990,4 +1090,14 @@
 	if ( fp )
 	{
+		if ( useMicrosoftBOM ) 
+		{
+			const unsigned char TIXML_UTF_LEAD_0 = 0xefU;
+			const unsigned char TIXML_UTF_LEAD_1 = 0xbbU;
+			const unsigned char TIXML_UTF_LEAD_2 = 0xbfU;
+
+			fputc( TIXML_UTF_LEAD_0, fp );
+			fputc( TIXML_UTF_LEAD_1, fp );
+			fputc( TIXML_UTF_LEAD_2, fp );
+		}
 		Print( fp, 0 );
 		fclose( fp );
@@ -1135,5 +1245,9 @@
 {
 	char buf [64];
-	sprintf (buf, "%d", _value);
+	#if defined(TIXML_SNPRINTF)		
+		TIXML_SNPRINTF(buf, sizeof(buf), "%d", _value);
+	#else
+		sprintf (buf, "%d", _value);
+	#endif
 	SetValue (buf);
 }
@@ -1142,14 +1256,18 @@
 {
 	char buf [256];
-	sprintf (buf, "%lf", _value);
+	#if defined(TIXML_SNPRINTF)		
+		TIXML_SNPRINTF( buf, sizeof(buf), "%lf", _value);
+	#else
+		sprintf (buf, "%lf", _value);
+	#endif
 	SetValue (buf);
 }
 
-const int TiXmlAttribute::IntValue() const
+int TiXmlAttribute::IntValue() const
 {
 	return atoi (value.c_str ());
 }
 
-const double  TiXmlAttribute::DoubleValue() const
+double  TiXmlAttribute::DoubleValue() const
 {
 	return atof (value.c_str ());
@@ -1206,9 +1324,23 @@
 
 
-void TiXmlText::Print( FILE* cfile, int /*depth*/ ) const
-{
-	TIXML_STRING buffer;
-	PutString( value, &buffer );
-	fprintf( cfile, "%s", buffer.c_str() );
+void TiXmlText::Print( FILE* cfile, int depth ) const
+{
+	if ( cdata )
+	{
+		int i;
+		fprintf( cfile, "\n" );
+		for ( i=0; i<depth; i++ ) {
+			fprintf( cfile, "    " );
+		}
+		fprintf( cfile, "<![CDATA[" );
+		fprintf( cfile, "%s", value.c_str() );	// unformatted output
+		fprintf( cfile, "]]>\n" );
+	}
+	else
+	{
+		TIXML_STRING buffer;
+		PutString( value, &buffer );
+		fprintf( cfile, "%s", buffer.c_str() );
+	}
 }
 
@@ -1216,5 +1348,12 @@
 void TiXmlText::StreamOut( TIXML_OSTREAM * stream ) const
 {
-	PutString( value, stream );
+	if ( cdata )
+	{
+		(*stream) << "<![CDATA[" << value << "]]>";
+	}
+	else
+	{
+		PutString( value, stream );
+	}
 }
 
@@ -1223,4 +1362,5 @@
 {
 	TiXmlNode::CopyTo( target );
+	target->cdata = cdata;
 }
 
